处理异常pl / sql:获取发生异常的值

时间:2016-10-14 10:30:43

标签: oracle plsql

我正在使用此代码

BEGIN
EXECUTE IMMEDIATE 'INSERT INTO MY_TABLE (A, B , C)
                  SELECT TABLE_2.A, TABLE_2.B, TABLE_2.C
                  FROM TABLE_2
                  WHERE TABLE_2.A in (val1,val2,val3) ';

EXCEPTION WHEN OTHERS then 
                PROC_EXCEPTION('ERROR',TABLE_2.B,SQLCODE,SQLERRM);
END;

我收到以下编译错误:

  

TABLE_2.B must be declared

如何获取发生异常的TABLE_2.B的值并将其传递给处理异常的过程?

2 个答案:

答案 0 :(得分:2)

您需要使用条款LOG ERRORS INTO https://oracle-base.com/articles/10g/dml-error-logging-10gr2

要创建错误日志表,请使用https://docs.oracle.com/cd/B19306_01/appdev.102/b14258/d_errlog.htm#CEGBBABI

然后在插入完成后,您可以处理错误表中的记录。

答案 1 :(得分:2)

您无法在num2words区块之外引用pip install num2words ...

尝试:

TABLE.A

要让EXECUTE IMMEDIATE的值在循环中执行:

BEGIN
EXECUTE IMMEDIATE 'INSERT INTO MY_TABLE (A, B , C)
              SELECT TABLE_2.A, TABLE_2.B, TABLE_2.C
              FROM TABLE_2
              WHERE TABLE_2.A in (val1,val2,val3) ';

EXCEPTION WHEN OTHERS then 
            PROC_EXCEPTION('ERROR with TABLE_2.B',SQLCODE,SQLERRM);
END;