0

我有以下代码结构

PROCEDURE .. 
    PRAGMA EXCEPTION_INIT(dml_errors, -24381);
    l_errors            NUMBER;

BEGIN
  -- busines logic
  FORALL TABLE_1 do delete;
  FORALL TABLE_1 do update;
  FORALL TABLE_1 do insert;
  FORALL TABLE_2 do insert;
  FORALL TABLE_2 do update;
  FORALL TABLE_2 do insert;
EXCEPTION
  WHEN dml_errors then
    --extract error indexes
END;

每个forall循环处理一个单独的数组表,即从table_1中删除的循环将处理一个由pls_integer索引的table_1_u表;

每个 forall 循环都有 save exceptions 关键字

现在,我如何提取哪些“for”失败和“该索引中的哪些记录失败”。

4

1 回答 1

3

我如何提取哪个“for”失败

使用调用堆栈(FORMAT_ERROR_BACKTRACE)或通过执行某种步骤:

PROCEDURE .. 
    PRAGMA EXCEPTION_INIT(dml_errors, -24381);
    l_errors            NUMBER;
    iStep NUMBER;
BEGIN
  -- busines logic
  iStep := 0;
  FORALL TABLE_1 do delete;
  iStep := 1;
  FORALL TABLE_1 do update;
  iStep := 2;
  FORALL TABLE_1 do insert;
  iStep := 3;
  FORALL TABLE_2 do insert;
  iStep := 4;
  FORALL TABLE_2 do update;
  iStep := 5;
  FORALL TABLE_2 do insert;
EXCEPTION
  WHEN dml_errors then
      IF iStep = 0 THEN
      ELSIF...
      END;
END;

该索引中的哪条记录失败

通过使用bulk_exceptions游标:

PROCEDURE .. 
    PRAGMA EXCEPTION_INIT(dml_errors, -24381);
    l_errors            NUMBER;
    iStep NUMBER;
BEGIN
  -- busines logic
  iStep := 0;
  FORALL TABLE_1 do delete;
  iStep := 1;
  FORALL TABLE_1 do update;
  iStep := 2;
  FORALL TABLE_1 do insert;
  iStep := 3;
  FORALL TABLE_2 do insert;
  iStep := 4;
  FORALL TABLE_2 do update;
  iStep := 5;
  FORALL TABLE_2 do insert;
EXCEPTION
  WHEN dml_errors then

      FOR i IN 1..SQL%BULK_EXCEPTIONS.COUNT LOOP
         DBMS_OUTPUT.PUT_LINE('Error #' || i || ' occurred during '|| 
            'iteration #' || SQL%BULK_EXCEPTIONS(i).ERROR_INDEX); 
             DBMS_OUTPUT.PUT_LINE('Error message is ' ||
             SQLERRM(-SQL%BULK_EXCEPTIONS(i).ERROR_CODE));
      END LOOP;

      IF iStep = 0 THEN
      ELSIF...
      END;
END;
于 2013-07-21T23:01:34.020 回答