show you BULK_EXCEPTIONS

see below

[@more@]

declare /* relies on... create table t ( text varchar2(3) ) */
type words_t is table of varchar2(10);
words words_t :=
words_t ( 'dog', 'fish', 'cat', 'ball', 'bat', 'spoke', 'pad' )
/* 'ball' and 'spoke' will raise ORA-01401 */;
n integer := 0;

type error_indexes_t is table of integer index by binary_integer;
error_indexes error_indexes_t;
type error_codes_t is table of varchar2(255) index by binary_integer;
error_codes error_codes_t;
type error_context_t is table of varchar2(255) index by binary_integer;
error_context error_context_t;
begin
for j in words.first..words.last
loop

begin
insert into t ( text ) values ( words(j) );
exception when others then
n := n+1; error_indexes(n) := j; error_codes(n) := SQLERRM;error_context(n):= words(j);
end;
end loop;
for j in 1..n
loop

Dbms_Output.Put_Line ( error_indexes(j) || ': ' || error_codes(j)||' error_context :='|| error_context(j));
end loop;
end;

--------at previous version handle dml exception only row by row

declare
type words_t is table of varchar2(10);
words words_t :=
words_t ( 'dog', 'fish', 'cat', 'ball', 'bat', 'spoke', 'pad' );
bulk_errors exception;
pragma exception_init ( bulk_errors, -24381 );
begin
forall j in words.first..words.last
save exceptions
insert into t ( text ) values ( words(j) );
exception when bulk_errors then

for m in 1..sql%bulk_exceptions.count
loop
Dbms_Output.Put_Line (
sql%bulk_exceptions(m).error_index || ', ' ||' error_row: '||words(m)||' '||
Sqlerrm(-sql%bulk_exceptions(m).error_code) );
end loop;
end;

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/66865/viewspace-933752/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/66865/viewspace-933752/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值