【问题标题】:How to obtain info from raise_application_error()?如何从 raise_application_error() 获取信息?
【发布时间】:2012-04-16 15:39:56
【问题描述】:
...PROCEDURE...
.....
WHEN DUP_VAL_ON_INDEX THEN
DBMS_OUTPUT.PUT_LINE(SQLCODE || ' ' || SQLERRM);
RAISE_APPLICATION_ERROR(-20021, 'Attempted to add duplicate primary key into table A2PROD');
.....

结果:

-1 ORA-00001: unique constraint (SYSTEM.SYS_C004235) violated

我想将结果显示为:

-20021 ORA-20021 Attempted to add duplicate primary key into table A2PROD

我尝试将 DOPL 放在 raise_application_error 函数之后,但仍然无法正常工作。 我想引发应用程序错误并获取错误消息和代码以将它们打印到 oracle 开发人员的输出控制台。

【问题讨论】:

    标签: oracle exception stored-procedures plsql


    【解决方案1】:

    我不完全确定我是否理解问题所在。如果DOPLdbms_output.put_line 的缩写,并且您希望SQLCODE 为-20021 并且SQLERRM 为“ORA-20021: Attempted to add duplicate primary key into table A2PROD”,您需要将dbms_output.put_line 调用捕获自定义错误消息的异常处理程序。当然,你也可以这样做

    WHEN dup_val_on_index
    THEN
      l_err_code := -20021;
      l_err_msg  := 'Attempted to add duplicate primary key into table A2PROD';
      dbms_output.put_line( l_err_code || ' ' || l_err_msg );
      raise_application_error( l_err_code, l_err_msg );
    END;
    

    【讨论】:

      【解决方案2】:

      发布的过程是从另一个过程调用的吗?还是您以其他方式运行它?

      RAISE_APPLICATION_ERROR 将异常编号及其消息传递给调用程序。那么 that 对异常有什么作用呢?例如,如果它有一个糟糕的异常处理程序,像这样......

           your_proc_here(p_new_id=>1);
      exception
          when others then
              null;
      end;
      

      ...您永远不会看到 -20021 错误,只会看到 DBMS_OUTPUT 输出。

      【讨论】:

        猜你喜欢
        • 2015-08-04
        • 2012-04-04
        • 2020-09-07
        • 2015-05-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多