您好,登錄后才能下訂單哦!
DECLARE
l_operator VARCHAR2(100);
l_year VARCHAR2(10);
l_month VARCHAR2(10);
l_xml_str VARCHAR2(4000); --xml字符串報文
l_xmltype xmltype;
BEGIN
--給定XML報文串
l_xml_str := '<?xml version="1.0" encoding="UTF-8"?>
<XMLMSG>
<INFO>
<OPERATOR>SMILE</OPERATOR>
<YEAR>2019</YEAR>
<MONTH>12</MONTH>
</INFO>
<STRARRAYS>
<STRARRAY>
<ID>1</ID>
<CODE>CODE1</CODE>
<NAME>NAME1</NAME>
</STRARRAY>
<STRARRAY>
<ID>2</ID>
<CODE>CODE2</CODE>
<NAME>NAME2</NAME>
</STRARRAY>
<STRARRAY>
<ID>3</ID>
<CODE>CODE3</CODE>
<NAME>NAME3</NAME>
</STRARRAY>
</STRARRAYS>
</XMLMSG>';
--將XML報文轉換成xmltype類型,便于后續解析
l_xmltype := xmltype.createxml(l_xml_str);
--普通簡單的解析字段值
SELECT xmlt.operator
,xmlt.year
,xmlt.month
INTO l_operator
,l_year
,l_month
FROM xmltable('$root/XMLMSG/INFO' passing l_xmltype AS "root" columns operator VARCHAR2(500) path 'OPERATOR'
,YEAR VARCHAR2(500) path 'YEAR'
,MONTH VARCHAR2(500) path 'MONTH') AS xmlt;
dbms_output.put_line('operator:' || l_operator || '--year:' || l_year || '--month:' || l_month);
--遍歷輸出二維數組
FOR rec_list IN (SELECT xmlt.id
,xmlt.code
,xmlt.name
INTO l_operator
,l_year
,l_month
FROM xmltable('$root/XMLMSG/STRARRAYS/STRARRAY' passing l_xmltype AS "root" columns id VARCHAR2(500) path 'ID'
,code VARCHAR2(500) path 'CODE'
,NAME VARCHAR2(500) path 'NAME') AS xmlt) LOOP
dbms_output.put_line(rec_list.id || '--' || rec_list.code || '--' || rec_list.name);
END LOOP;
EXCEPTION
WHEN fnd_api.g_exc_error THEN
dbms_output.put_line('error:' || SQLCODE || '--' || SQLERRM);
WHEN fnd_api.g_exc_unexpected_error THEN
dbms_output.put_line('Unexpected_error.' || SQLCODE || '--' || SQLERRM);
WHEN OTHERS THEN
dbms_output.put_line('Other error:' || SQLCODE || '--' || SQLERRM);
END;
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。