1
如何在xmltable的xpath中傳遞變量值?如何在xmltable中傳遞值
DECLARE
v NUMBER := 0;
BEGIN
SELECT *
FROM xml_billrun_files t ,
xmltable('/invoice/AR_ITEMS[@elem='||v||']/ITEMS/USAGE_RECORDS/SESSION_INFO'
passing t.update_xmldoc
columns chrg_duration VARCHAR2(20) path 'DURATION',
amount NUMBER path 'AMOUNT') x;
END;
我試過這一個。
DECLARE
v NUMBER := 0;
BEGIN
SELECT *
FROM xml_billrun_files t ,
xmltable('/invoice/AR_ITEMS[@elem=$i]/ITEMS/USAGE_RECORDS/SESSION_INFO'
passing t.update_xmldoc, xmltype(v) as "i"
columns chrg_duration VARCHAR2(20) path 'DURATION',
amount NUMBER path 'AMOUNT') x;
END;
但它返回一個錯誤:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00210: expected '<' instead of '0'
Error at line 1
ORA-06512: at "SYS.XMLTYPE", line 310
ORA-06512: at line 1
ORA-06512: at line 5
31011. 00000 - "XML parsing failed"
*Cause: XML parser returned an error while trying to parse the document.
*Action: Check if the document to be parsed is valid.
感謝您的幫助。
但在這樣做,用FOR循環,生病得到錯誤'錯誤(674,46):PL/SQL:ORA-00932:不一致的數據類型:預期 - 得到NATIVE INTEGER' – NelzKi
@ NelzKi - 是的,對上一個問題的回答是錯誤的,我已經糾正了這兩個問題。您需要將循環變量轉換爲SQL數字類型。 –
我明白了..謝謝你的幫助..:D – NelzKi