Oracle 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 错误消息没有显示约束名称,即它显示违反了检查约束(.)
,但这并没有告诉我违反了哪个检查约束。
有谁知道这是怎么回事?
(Oracle 版本 10.2)
I am catching errors from a bulk insert operation like this:
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;
The output looks something like this:
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
The fact that I'm getting errors does not bother me, as I am testing error-handling code. The problem is that the Oracle error message is not displaying the the constraint names, i.e. it displays check constraint (.) violated
but that doesn't tell me WHICH check constraint I violated.
Does anyone know what's up with this?
(Oracle version 10.2)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SQL%BULK_EXCEPTIONS(i).error_code仅保存Oracle错误号。然后,您可以使用 sqlerrm 函数查找错误消息文本。该函数无法知道什么约束被打破。
您可以调用 sqlerrm 函数,而不会抛出异常来复制结果。
哪个输出
一个可能的解决方法是在异常处理程序中重新执行失败的语句。
表定义:
代码:
输出:
SQL%BULK_EXCEPTIONS(i).error_code only saves the Oracle error number. You are then using the sqlerrm function to look up the error message text. That function would have no way of knowing what constraint is being broken.
You can call the sqlerrm function without an exception being thrown to duplicate your results.
Which outputs
A possible workaround would be to reexecute the failed statement in the exception handler.
Table Def:
Code:
Which outputs: