3
甲骨文DML错误,我从一个大容量插入操作捕捉错误是这样的:缺乏细节
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
是我得到的错误确实的事实不打扰我,因为我正在测试错误处理代码。问题在于Oracle错误消息没有显示约束名称,即它显示check constraint (.) violated
,但它并不告诉我我违反了哪个检查约束。
有人知道这是怎么回事吗?
(Oracle版本10.2)
@Daniel Emge:嗯是的,这是有道理的。射击!我猜%BULK_EXCEPTIONS不存储具体错误的细节,所以我想要做的可能是不可能的。 – FrustratedWithFormsDesigner 2010-01-27 18:50:47
我想到了一个解决方法。您可以针对失败的每一行重新执行异常处理程序中的语句。然后您可以捕获具有约束名称的异常。 – 2010-01-27 19:13:24
嘿,这很聪明!谢谢! :) – FrustratedWithFormsDesigner 2010-01-27 20:46:20