缺少详细信息的Oracle DML错误
我正在捕获批量插入操作中的错误,如下所示:缺少详细信息的Oracle DML错误,oracle,plsql,ora-00001,ora-01400,ora-02290,Oracle,Plsql,Ora 00001,Ora 01400,Ora 02290,我正在捕获批量插入操作中的错误,如下所示: begin --bulk insert forall i in v_data.first .. v_data.last save exceptions insert into my_filter_table values v_data (i); commit; exception -- catch and print the saved-up DML errors. when X_DML_ER
begin
--bulk insert
forall i in v_data.first .. v_data.last save exceptions
insert into my_filter_table values v_data (i);
commit;
exception
-- catch and print the saved-up DML errors.
when X_DML_ERRORS then
declare
v_iteration number;
begin
dbms_output.put_line('');
dbms_output.put_line('DML Errors:');
for i in 1 .. SQL%BULK_EXCEPTIONS.count loop
v_iteration := SQL%BULK_EXCEPTIONS(i).error_index;
dbms_output.put_line('Iteration: '||v_iteration||' Message: '||
SQLERRM(-SQL%BULK_EXCEPTIONS(i).ERROR_CODE));
end loop;
end;
end;
Iteration: 3 Message: ORA-01400: cannot insert NULL into ()
Iteration: 4 Message: ORA-02290: check constraint (.) violated
Iteration: 8 Message: ORA-00001: unique constraint (.) violated
输出如下所示:
begin
--bulk insert
forall i in v_data.first .. v_data.last save exceptions
insert into my_filter_table values v_data (i);
commit;
exception
-- catch and print the saved-up DML errors.
when X_DML_ERRORS then
declare
v_iteration number;
begin
dbms_output.put_line('');
dbms_output.put_line('DML Errors:');
for i in 1 .. SQL%BULK_EXCEPTIONS.count loop
v_iteration := SQL%BULK_EXCEPTIONS(i).error_index;
dbms_output.put_line('Iteration: '||v_iteration||' Message: '||
SQLERRM(-SQL%BULK_EXCEPTIONS(i).ERROR_CODE));
end loop;
end;
end;
Iteration: 3 Message: ORA-01400: cannot insert NULL into ()
Iteration: 4 Message: ORA-02290: check constraint (.) violated
Iteration: 8 Message: ORA-00001: unique constraint (.) violated
迭代:3消息:ORA-01400:无法在()中插入NULL
迭代:4消息:ORA-02290:检查约束(.)已违反
迭代:8消息:ORA-00001:违反了唯一约束(.)
我得到错误的事实并不困扰我,因为我正在测试错误处理代码。问题是Oracle错误消息没有显示约束名称,即它显示了检查约束(.)违犯
,但没有告诉我违反了哪个检查约束
有人知道这是怎么回事吗
(Oracle 10.2版)SQL%BULK\u异常(i)。错误代码仅保存Oracle错误号。然后使用sqlerrm函数查找错误消息文本。该函数将无法知道什么约束被打破
您可以调用sqlerrm函数,而不会引发异常以复制结果
begin
dbms_output.put_Line(sqlerrm(-1400));
dbms_output.put_Line(sqlerrm(-2290));
dbms_output.put_Line(sqlerrm(-1));
end;
哪个输出
ORA-01400: cannot insert NULL into ()
ORA-02290: check constraint (.) violated
ORA-00001: unique constraint (.) violated
一种可能的解决方法是在异常处理程序中重新执行失败的语句
表Def:
create table t ( x number(1) primary key);
代码:
哪些产出:
ORA-01438: value larger than specified precision allowed for this column
ORA-00001: unique constraint (XXXXXXXX.SYS_C00264470) violated
ORA-24381: error(s) in array DML
@丹尼尔·埃姆:嗯,是的,这很有道理。射击我想%BULK_异常不会存储特定错误的详细信息,因此我尝试执行的操作可能是不可能的。我想到了一个解决方法。您可以在异常处理程序中为失败的每一行重新执行该语句。然后,您可以捕获具有约束名称的异常。嘿,这太聪明了!谢谢!:)