Converting XML message to PL/SQL record type [message #450568] |
Thu, 08 April 2010 00:42  |
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 #450770 is a reply to message #450625] |
Fri, 09 April 2010 02:39   |
_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
|
|
|
|