暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Oracle 在插入过程中处理旁路故障并继续

ASKTOM 2020-08-19
271

问题描述

嗨,汤姆

我的过程中有1000插入,如果第100插入失败,我将如何处理?
理想情况下,我需要绕过100个,继续到最后。
代码示例:-

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

专家解答

使用DML错误日志记录:

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
复制

文章转载自ASKTOM,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论