oracle 获取更新数目,oracle - 受PL / SQL中UPDATE影响的行数

SQL%ROWCOUNT也可以在不分配的情况下使用(至少从Oracle 11g开始)。

只要在当前块中未执行任何操作(更新,删除或插入),就会将SQL%ROWCOUNT设置为null。 然后它保持受最后一次DML操作影响的行数:

说我们有表CLIENT

create table client (

val_cli integer

,status varchar2(10)

)

/

我们会这样测试:

begin

dbms_output.put_line('Value when entering the block:'||sql%rowcount);

insert into client

select 1, 'void' from dual

union all select 4, 'void' from dual

union all select 1, 'void' from dual

union all select 6, 'void' from dual

union all select 10, 'void' from dual;

dbms_output.put_line('Number of lines affected by previous DML operation:'||sql%rowcount);

for val in 1..10

loop

update client set status = 'updated' where val_cli = val;

if sql%rowcount = 0 then

dbms_output.put_line('no client with '||val||' val_cli.');

elsif sql%rowcount = 1 then

dbms_output.put_line(sql%rowcount||' client updated for '||val);

else -- >1

dbms_output.put_line(sql%rowcount||' clients updated for '||val);

end if;

end loop;

end;

导致:

Value when entering the block:

Number of lines affected by previous DML operation:5

2 clients updated for 1

no client with 2 val_cli.

no client with 3 val_cli.

1 client updated for 4

no client with 5 val_cli.

1 client updated for 6

no client with 7 val_cli.

no client with 8 val_cli.

no client with 9 val_cli.

1 client updated for 10

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值