sql%bulk_rowcount 的使用

说明:

%BULK_ROWCOUNT 属性计算FORALL迭代影响行数
  在进行SQL数据操作语句时,SQL引擎打开一个隐式游标(命名为SQL),该游标的标量属性(scalar attribute)有 %FOUND, %ISOPEN, %NOTFOUND, and %ROWCOUNT。
  FORALL语句除具有上边的标量属性外,还有个复合属性(composite  attribute):%BULK_ROWCOUNT,该属性具有索引表(index-by  table)语法。它的第i个元素存贮SQL语句(INSERT,  UPDATE或DELETE)第i个执行的处理行数。如果第i个执行未影响行,%bulk_rowcount  (i),返回0。FORALL与%bulk_rowcount属性使用相同下标

--代码 :

 1 /*
 2 drop table TESTT ;
 3 CREATE TABLE TESTT(TID varchar2(100)) ;
 4 TRUNCATE TABLE TESTT ;
 5 SELECT * FROM TESTT ;
 6 
 7 */
 8 
 9 DECLARE
10   type stp_index is table of sys_product.productcode%type;
11   --idx_tab stp_index :=number_index(null) ;
12   idx_tab stp_index;
13   cursor cur_stp is
14     select productcode pcode from sys_product;
15 
16 BEGIN
17 ----新增 
18  open cur_stp;
19   loop
20     fetch cur_stp bulk collect
21       into idx_tab;
22     exit when cur_stp%notfound;
23   end loop;
24    close cur_stp ;
25   forall cur in idx_tab.first .. idx_tab.last
26     insert into testt values (idx_tab(cur));
27       dbms_output.put_line('insert --------------' ||sql%rowcount);
28   for i in idx_tab.first .. idx_tab.count loop
29     dbms_output.put_line(idx_tab(i)||' insert 受影响行为 ' || sql%bulk_rowcount(i)||' 行 !');
30   end loop;
31   COMMIT;
32 --修改
33   forall cur in idx_tab.first .. idx_tab.last
34    update testt set tid=idx_tab(cur)||' % ' where tid=idx_tab(cur);
35       dbms_output.put_line('update --------------' ||sql%rowcount);
36    for i in idx_tab.first .. idx_tab.count loop
37     dbms_output.put_line(idx_tab(i)||' update 受影响行为 ' || sql%bulk_rowcount(i)||' 行 !       '||  sql%rowcount);
38   end loop; 
39 END;

---结果:

 1 insert --------------19
 2 GFWD insert 受影响行为 1 行 !
 3 GOPTION insert 受影响行为 1 行 !
 4 NCD insert 受影响行为 1 行 !
 5 GLS insert 受影响行为 1 行 !
 6 IBO insert 受影响行为 1 行 !
 7 REPO insert 受影响行为 1 行 !
 8 OBPO insert 受影响行为 1 行 !
 9 BSD insert 受影响行为 1 行 !
10 DEPO insert 受影响行为 1 行 !
11 IRS insert 受影响行为 1 行 !
12 FXSWAP insert 受影响行为 1 行 !
13 FRA insert 受影响行为 1 行 !
14 IBL insert 受影响行为 1 行 !
15 FXFWD insert 受影响行为 1 行 !
16 CCS insert 受影响行为 1 行 !
17 FXOPTION insert 受影响行为 1 行 !
18 GSWAP insert 受影响行为 1 行 !
19 BSDC insert 受影响行为 1 行 !
20 CI insert 受影响行为 1 行 !
21 update --------------19
22 GFWD update 受影响行为 1 行 !       19
23 GOPTION update 受影响行为 1 行 !       19
24 NCD update 受影响行为 1 行 !       19
25 GLS update 受影响行为 1 行 !       19
26 IBO update 受影响行为 1 行 !       19
27 REPO update 受影响行为 1 行 !       19
28 OBPO update 受影响行为 1 行 !       19
29 BSD update 受影响行为 1 行 !       19
30 DEPO update 受影响行为 1 行 !       19
31 IRS update 受影响行为 1 行 !       19
32 FXSWAP update 受影响行为 1 行 !       19
33 FRA update 受影响行为 1 行 !       19
34 IBL update 受影响行为 1 行 !       19
35 FXFWD update 受影响行为 1 行 !       19
36 CCS update 受影响行为 1 行 !       19
37 FXOPTION update 受影响行为 1 行 !       19
38 GSWAP update 受影响行为 1 行 !       19
39 BSDC update 受影响行为 1 行 !       19
40 CI update 受影响行为 1 行 !       19

猜你喜欢

转载自www.cnblogs.com/linbo3168/p/9026215.html
今日推荐