【筆記】forall 異常捕獲

yellowlee發表於2009-03-31

forall 的異常捕獲,示例

DECLARE
  TYPE NumList IS TABLE OF NUMBER;
  num_tab NumList := NumList(10, 0, 11, 12, 30, 0, 20, 199, 2, 0, 9, 1);
  errors  NUMBER;
  dml_errors EXCEPTION;
  PRAGMA exception_init(dml_errors, -24381);
BEGIN
  FORALL i IN num_tab.FIRST .. num_tab.LAST SAVE EXCEPTIONS
    DELETE FROM emp WHERE sal > 500000 / num_tab(i);
EXCEPTION
  WHEN dml_errors THEN
    errors := SQL%BULK_EXCEPTIONS.COUNT;
    dbms_output.put_line('Number of errors is ' || errors);
    FOR i IN 1 .. errors LOOP
      dbms_output.put_line('Error ' || i || ' occurred during' ||
                           'iteration ' || SQL%BULK_EXCEPTIONS(i)
                           .ERROR_INDEX);
      dbms_output.put_line('Oracle error is' ||
                           SQLERRM(-SQL%BULK_EXCEPTIONS(i).ERROR_CODE));
    END LOOP;
END;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/16179598/viewspace-582296/,如需轉載,請註明出處,否則將追究法律責任。

相關文章