加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

记录oracle中的行号

发布时间:2020-12-12 16:24:37 所属栏目:百科 来源:网络整理
导读:我目前正在处理程序中的日志错误.此过程的目标是在DB中的其他包中的异常处理程序中调用,并记录每个程序遇到的错误.下面是我的代码. CREATE OR REPLACE PROCEDURE APMS.test_procedure AS procedure write_error_log (errcode number,errstr varchar2) is pra
我目前正在处理程序中的日志错误.此过程的目标是在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;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读