oracle怎么抛错误,oracle – 如何确定PL / SQL语句中的行/值抛出错误?

使用SAVE EXCEPTIONS子句的解决方案:

SQL> create table my_table (my_column)

2 as

3 select level from dual connect by level <= 9

4 /

Table created.

SQL> create function do_something

2 ( p_my_column in my_table.my_column%type

3 ) return my_table.my_column%type

4 is

5 begin

6 return 10 + p_my_column;

7 end;

8 /

Function created.

SQL> alter table my_table add check (my_column not in (12,14))

2 /

Table altered.

SQL> declare

2 e_forall_error exception;

3 pragma exception_init(e_forall_error,-24381)

4 ;

5 type t_my_columns is table of my_table.my_column%type;

6 a_my_columns t_my_columns := t_my_columns()

7 ;

8 begin

9 select my_column

10 bulk collect into a_my_columns

11 from my_table

12 ;

13 forall i in 1..a_my_columns.count save exceptions

14 update my_table

15 set my_column = do_something(a_my_columns(i))

16 where my_column = a_my_columns(i)

17 ;

18 exception

19 when e_forall_error then

20 for i in 1..sql%bulk_exceptions.count

21 loop

22 dbms_output.put_line(a_my_columns(sql%bulk_exceptions(i).error_index));

23 end loop;

24 end;

25 /

2

4

PL/SQL procedure successfully completed.

对于非常大的数据集,您可能不希望炸毁PGA内存,因此在这种情况下一定要使用LIMIT子句.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值