是否可以捕获发生异常的行?
给出以下PL / SQL块:
l_path1_value := l_xmltype.extract('/SOME_PATH1').getStringVal();
l_path2_value := l_xmltype.extract('/SOME_PATH2').getStringVal();
l_path3_value := l_xmltype.extract('/SOME_PATH3').getStringVal();
当extract
函数返回null
时,将抛出SELF_IS_NULL
异常。抛出错误时是否可以获取错误行?
WHEN SELF_IS_NULL THEN
--get error line and save it somewhere
答案 0 :(得分:0)
尝试为extract
函数创建一个包装函数,并定义一个EXCEPTION SELF_IS_NULL
并在它返回NULL时使用RAISE SELF_IS_NULL;
。
dbms_output.put_line( SQLERRM||chr(10)||dbms_utility.format_error_backtrace );
请把它放在你的例外程序块中。它从它的起源位置打印堆栈跟踪(行号)
答案 1 :(得分:0)
实现此目的的一种方法是使用检查点变量,类似于以下内容:
BEGIN
strXMLelement := '/SHOW_SHIPMENT_005/DATAAREA/SHOW_SHIPMENT/SHIPMENT/SHIPITEM/QUANTITY/VALUE/text()';
l_XMLvalue := l_xmltype.extract(strXMLelement ).getStringVal();
dbms_output.put_line('QUANTITY: '||l_XMLvalue);
strXMLelement := '/SHOW_SHIPMENT_005/DATAAREA/SHOW_SHIPMENT/SHIPMENT/SHIPITEM/DOCUMNTREF/DOCUMENTID/text()';
l_XMLdocument_id := l_xmltype.extract(strXMLelement ).getStringVal();
dbms_output.put_line('DOCUMENT ID:' ||l_XMLdocument_id);
strXMLelement := '/SHOW_SHIPMENT_005/DATAAREA/SHOW_SHIPMENT/SHIPMENT/SHIPITEM/DOCUMNTREF/USERAREA/DOCUMENTRELEASE/text()';
l_XMLdoc_release := l_xmltype.extract(strXMLelement).getStringVal();
dbms_output.put_line('DOCUMENT RELEASE:' ||l_XMLdoc_release);
strXMLelement := '/SHOW_SHIPMENT_005/DATAAREA/SHOW_SHIPMENT/SHIPMENT/SHIPITEM/DOCUMNTREF/LINENUM/text()';
l_XMLlinenum := l_xmltype.extract(strXMLelement).getStringVal();
dbms_output.put_line('LINE NUMBER:' ||l_XMLlinenum);
strXMLelement := '/SHOW_SHIPMENT_005/DATAAREA/SHOW_SHIPMENT/SHIPMENT/SHIPITEM/DOCUMNTREF/SCHLINENUM/text()';
l_XMLsch_lnum := l_xmltype.extract(strXMLelement).getStringVal();
dbms_output.put_line('SCHIPMENT LINE NUMBER:' ||l_XMLsch_lnum);
EXCEPTION
WHEN SELF_IS_NULL THEN
DBMS_OUTPUT.PUT_LINE('Error extracting ' || strXMLelement || ' : ' ||
'SQLCODE=' || SQLCODE || ' SQLERRM=' || SQLERRM);
END;
分享并享受。