Skip to Main Content
  • Questions
  • Handling bypass failures during inserts and continue

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question.

Asked: August 19, 2020 - 6:50 pm UTC

Last updated: August 21, 2020 - 9:07 am UTC

Version: 12c

Viewed 1000+ times

You Asked

Hi Tom

I am having 1000 inserts in my procedure and if 100th insert fails, how will i handle that?
Ideally i need to bypass that 100th one and continue till end.
Code example:-

Begin
insert into table () values();
insert into table () values();
.
.
.
commit;
end;

and Chris said...

Use DML error logging:

create table t (
  c1 int primary key 
);

exec dbms_errlog.create_error_log (dml_table_name => 't');

begin
  insert into t values ( 1 )
    log errors reject limit unlimited;
  insert into t values ( 2 )
    log errors reject limit unlimited;
  insert into t values ( 1 )
    log errors reject limit unlimited;
  insert into t values ( 'a' )
    log errors reject limit unlimited;
  insert into t values ( 3 )
    log errors reject limit unlimited;
end;
/

select * from t;

C1   
    1 
    2 
    3 

select c1, ora_err_mesg$ 
from   err$_t;

C1    ORA_ERR_MESG$                                                 
1     ORA-00001: unique constraint (CHRIS.SYS_C0019292) violated
a     ORA-01722: invalid number


Is this answer out of date? If it is, please let us know via a Comment

More to Explore

SQL

The Oracle documentation contains a complete SQL reference.