--Oracle異常返回完整信息,具體見最後附
--當然最好選取返回的信息連同代碼其他相關信息
--如發生對象名、時間等插入預建備查錯誤表
--11:08 2007-11-26 edit by inreyou
declare
strName Varchar2(20);
begin
strName := ''DataNotFound''; --DataNotFound
if strName = ''DivideIsZero'' then
RAISE ZERO_DIVIDE;
elsif strName = ''DataNotFound'' then
RAISE NO_DATA_FOUND;
end if;
exception
when ZERO_DIVIDE then
dbms_output.put_line(''EXCEPTION IN ZERO_DIVIDE'');
when others then
dbms_output.put_line(''EXCEPTION IN OTHERS'');
dbms_output.put_line(chr(13) || chr(10) || ''SQLCODE:'');
dbms_output.put_line(SQLCODE);
dbms_output.put_line(chr(13) || chr(10) || ''SQLERRM:'');
dbms_output.put_line(SQLERRM);
dbms_output.put_line(chr(13) || chr(10) ||
''DBMS_UTILITY.FORMAT_ERROR_STACK(完整的錯誤消息):'');
dbms_output.put_line(DBMS_UTILITY.FORMAT_ERROR_STACK);
dbms_output.put_line(chr(13) || chr(10) ||
''DBMS_UTILITY.FORMAT_ERROR_BACKTRACE(發生異常時異常點的堆棧信息):'');
dbms_output.put_line(DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);
dbms_output.put_line(chr(13) || chr(10) ||
''DBMS_UTILITY.FORMAT_CALL_STACK(程序當前執行點的堆棧信息):'');
dbms_output.put_line(DBMS_UTILITY.FORMAT_CALL_STACK);
end;
/*
附:
EXCEPTION IN OTHERS
SQLCODE:
100
SQLERRM:
ORA-01403: 未找到數據
DBMS_UTILITY.FORMAT_ERROR_STACK(完整的錯誤消息):
ORA-01403: 未找到數據
DBMS_UTILITY.FORMAT_ERROR_BACKTRACE(發生異常時異常點的堆棧信息):
ORA-06512: 在 line 12
DBMS_UTILITY.FORMAT_CALL_STACK(程序當前執行點的堆棧信息):
----- PL/SQL Call Stack -----
object line object
handle number name
673AAB40 46 anonymous block
*/