我目前正在处理程序中的日志错误.此过程的目标是在DB中的其他包中的异常处理程序中调用,并记录每个程序遇到的错误.下面是我的代码.
CREATE OR REPLACE PROCEDURE APMS.test_procedure AS procedure write_error_log (errcode number,errstr varchar2) is pragma autonomous_transaction; -- this procedure stays in its own new private transaction begin INSERT INTO error_log (ora_err_tmsp,ora_err_number,ora_err_msg,ora_err_line_no) values (CURRENT_TIMESTAMP,errcode,errstr,'line number'); COMMIT; -- this commit does not interfere with the caller's transaction. end write_error_log; BEGIN INSERT INTO mockdata VALUES ('data1','mockname','mockcity'); exception when others then write_error_log(sqlcode,sqlerrm); raise; END test_procedure; /
我目前只是在我的mock_data表中引发错误,以记录error_log表中的错误,看看它的功能是否只是无法弄清楚如何记录行号列.我是一个完全的初学者,所以任何帮助都会赞赏. Addiotionally,如果有人知道如何在其他软件包/过程中使用此过程来记录其他软件包中的错误,那也是很棒的.我在这里学习,所以任何反馈都表示赞赏,如果我不清楚,我可以进一步扩展这篇文章.
尝试使用DBMS_UTILITY.FORMAT_ERROR_BACKTRACE.您可以查看
here以获取更多信息.
像这样的东西应该使你的代码工作:
CREATE OR REPLACE PROCEDURE APMS.test_procedure AS procedure write_error_log (errcode number,errstr varchar2,errline varchar2) is pragma autonomous_transaction; -- this procedure stays in its own new private transaction begin INSERT INTO error_log (ora_err_tmsp,errline); COMMIT; -- this commit does not interfere with the caller's transaction. end write_error_log; BEGIN INSERT INTO mockdata VALUES ('data1',sqlerrm,DBMS_UTILITY.FORMAT_ERROR_BACKTRACE); raise; END test_procedure;