Home » SQL & PL/SQL » SQL & PL/SQL » Converting XML message to PL/SQL record type (Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production)
Converting XML message to PL/SQL record type [message #450568] Thu, 08 April 2010 00:42 Go to next message
himang
Messages: 282
Registered: March 2005
Location: Bangalore
Senior Member

Hi,
We have a queue in which the message is coming from external system. The payload of the queue table is a PL/SQL record type. Once we get the message in the queue, we de-queue the message and read through the PL/SQL type collection and process the message.

From the below query, we are able to convert the PL/SQL collection message to XML message and see the data.

SELECT dbms_xmlgen.getxml
('SELECT USER_DATA 
FROM <Queue_table> X 
WHERE X.USER_DATA.SALE_ORDER.P_HEADER_REC.ORIG_SYS_DOCUMENT_REF=800501298') 
FROM dual;


The new requirement is the message would come in a XML message in the queue. So my question is, is there any way through which the XML message can be converted to the PL/SQL record structure directly (it would be the opposite operation of the above query).

Thanks in advance.

[Updated on: Thu, 08 April 2010 01:28] by Moderator

Report message to a moderator

Re: Converting XML message to PL/SQL record type [message #450616 is a reply to message #450568] Thu, 08 April 2010 06:20 Go to previous messageGo to next message
ramoradba
Messages: 2457
Registered: January 2009
Location: AndhraPradesh,Hyderabad,I...
Senior Member
if i understood properly the following may help you....

http://it.toolbox.com/blogs/oracle-guide/plxml-xml-based-scripting-for-plsql-11642

And
http://code.google.com/p/pl-xml/downloads/list

Good luck

sriram Smile
Re: Converting XML message to PL/SQL record type [message #450625 is a reply to message #450616] Thu, 08 April 2010 07:23 Go to previous messageGo to next message
himang
Messages: 282
Registered: March 2005
Location: Bangalore
Senior Member

Thanks for that. But was not looking for the program to do that..

Was looking if there is a direct API provided by Oracle (similar I gave as the select statement). Was wondering, if any API is there which takes the XMLType/CLOB as input and gives the record type as output (with data embedded)...
Re: Converting XML message to PL/SQL record type [message #450770 is a reply to message #450625] Fri, 09 April 2010 02:39 Go to previous messageGo to next message
_jum
Messages: 577
Registered: February 2008
Senior Member
Hope this is what you are looking for:
--create needed SQL TYPE
CREATE OR REPLACE TYPE my_tab_row_type AS OBJECT (
  tabnam   VARCHAR2 (30),
  nrows    NUMBER
);
/

--test TYPE
SELECT my_tab_row_type (table_name, num_rows) xstr
  FROM user_tables
 WHERE ROWNUM <= 3;

--select as XML, use DBMS_XMLGEN.getxmltype !
WITH xml_data AS
 (SELECT DBMS_XMLGEN.getxmltype
   ('SELECT table_name, num_rows, blocks FROM user_tables WHERE rownum<=3') xstr FROM DUAL)
SELECT *
  FROM xml_data;

--select as TYPE via XML
WITH xml_data AS
 (SELECT DBMS_XMLGEN.getxmltype
   ('SELECT table_name, num_rows, blocks FROM user_tables WHERE rownum<=3') xstr FROM DUAL)
SELECT my_tab_row_type 
        (EXTRACTVALUE (COLUMN_VALUE, '//TABLE_NAME'),EXTRACTVALUE (COLUMN_VALUE, '//NUM_ROWS')) mtrt
  FROM xml_data, TABLE (XMLSEQUENCE (EXTRACT (xstr, '//ROW'))) 

MTRT                                              
--------------------------------------------------
(TAB_A; 2)                        
(TAB_B; 19)                      
(TAB_C; 171)                      

3 rows selected.

[Updated on: Fri, 09 April 2010 02:41]

Report message to a moderator

Re: Converting XML message to PL/SQL record type [message #450819 is a reply to message #450625] Fri, 09 April 2010 07:06 Go to previous message
ramoradba
Messages: 2457
Registered: January 2009
Location: AndhraPradesh,Hyderabad,I...
Senior Member
himang wrote on Thu, 08 April 2010 17:53
Thanks for that. But was not looking for the program to do that..

Was looking if there is a direct API provided by Oracle (similar I gave as the select statement). Was wondering, if any API is there which takes the XMLType/CLOB as input and gives the record type as output (with data embedded)...


sriram Smile
Previous Topic: ORA-31186 and ORA-06512
Next Topic: need help for a beginner
Goto Forum:
  


Current Time: Fri Jun 20 00:08:04 CDT 2025