CREATE TABLE tmp_table (aaa VARCHAR2(100) NOT NULL); DECLARE TYPE t_varchar IS TABLE OF VARCHAR2(100) INDEX BY BINARY_INTEGER; a_varchar t_varchar; e_bulk_errors EXCEPTION; t_error_index PLS_INTEGER; PRAGMA EXCEPTION_INIT(e_bulk_errors,-24381); BEGIN a_varchar(1) := 'aaa'; a_varchar(2) := NULL; a_varchar(4) := NULL; a_varchar(5) := 'eee'; a_varchar(7) := 'fff'; a_varchar(8) := 'ggg'; a_varchar(9) := NULL; FORALL i IN INDICES OF a_varchar SAVE EXCEPTIONS INSERT INTO tmp_table (aaa) VALUES (a_varchar(i)); EXCEPTION WHEN e_bulk_errors THEN FOR i IN 1..SQL%bulk_exceptions.COUNT LOOP t_error_index := SQL%BULK_EXCEPTIONS(i).error_index; dbms_output.put_line(i||' error code '||SQL%BULK_EXCEPTIONS(i).error_code); dbms_output.put_line(i||' error index '||t_error_index); END LOOP; END;
One drawback here is the t_error_index. That’s not the index from a_varchar, but an sequential index. So in this case the last error is raised for a_varchar(9). But sequential this is the 7th record in the plsql table. so in this case t_error_index containt number 7 and NOT 9. Be assured to have n index in a_varchar without gaps.