Search notes:

Oracle: DBMS_ERRLOG

dbms_errlog consists of one procedure only: create_error_log. This procedure creates error logging tables into which DML statements can write records that caused an error. Thus, DML statements can continue without potentially stopping an entire load in a DWH environment.

Example

Create a table (tq84_src) which will contain the data that is attempted to be filled into the destination table tq84_dest:
create table tq84_src (
   id   number(2),
   txt  varchar2(20) not null,
   num  number
);

create table tq84_dest (
   id   number(2),
   txt  varchar2(20) not null,
   num  number,
   constraint tq84_err_log_pk primary key(id)
);
Github repository Oracle-Patterns, path: /Installed/dbms/errlog/table.sql
Create the error table:
begin
   dbms_errlog.create_error_log(
      'tq84_dest',
      'tq84_dest_err'
   );
end;
/
Github repository Oracle-Patterns, path: /Installed/dbms/errlog/error-table.sql
Fill the source table:
insert into tq84_src values (1, 'def'  , 7);
insert into tq84_src values (2, 'nop'  , 9);
insert into tq84_src values (3, 'abc'  , 0);
insert into tq84_src values (4, 'klm'  , 6);
insert into tq84_src values (5, 'nop'  , 6);
insert into tq84_src values (6, 'qrs'  , 9);
insert into tq84_src values (4, 'tuv'  , 2);
Github repository Oracle-Patterns, path: /Installed/dbms/errlog/insert-src.sql
Try to insert data into the dest table. Without error log clause, the first statement would fail with a primary key violation and a division by zero error:
begin

   insert into tq84_dest
   select
      id,
      txt || '!',
      42/num
   from
      tq84_src
   log errors into tq84_dest_err
--
-- Log all errors:
--
   reject limit unlimited;


   insert into tq84_dest values (99, '2nd statement', 42);

end;
/
Github repository Oracle-Patterns, path: /Installed/dbms/errlog/insert-dest.sql
Because of the error log clause, we can find the errors in the error log table:
select
   ora_err_number$,
   ora_err_mesg$,
   id,
   txt,
   num
from
   tq84_dest_err;
Github repository Oracle-Patterns, path: /Installed/dbms/errlog/select.sql

See also

Oracle: INSERT statement - LOG ERRORS INTO clause
Oracle DBMS PL/SQL packages

Index