说明:

%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属性使用相同下标

--%bulk_rowcount 代码 :

 /*
drop table TESTT ;
CREATE TABLE TESTT(TID varchar2(100)) ;
TRUNCATE TABLE TESTT ;
SELECT * FROM TESTT ; */ DECLARE
type stp_index is table of sys_product.productcode%type;
--idx_tab stp_index :=number_index(null) ;
idx_tab stp_index;
cursor cur_stp is
select productcode pcode from sys_product; BEGIN
----新增
open cur_stp;
loop
fetch cur_stp bulk collect
into idx_tab;
exit when cur_stp%notfound;
end loop;
close cur_stp ;
forall cur in idx_tab.first .. idx_tab.last
insert into testt values (idx_tab(cur));
dbms_output.put_line('insert --------------' ||sql%rowcount);
for i in idx_tab.first .. idx_tab.count loop
dbms_output.put_line(idx_tab(i)||' insert 受影响行为 ' || sql%bulk_rowcount(i)||' 行 !');
end loop;
COMMIT;
--修改
forall cur in idx_tab.first .. idx_tab.last
update testt set tid=idx_tab(cur)||' % ' where tid=idx_tab(cur);
dbms_output.put_line('update --------------' ||sql%rowcount);
for i in idx_tab.first .. idx_tab.count loop
dbms_output.put_line(idx_tab(i)||' update 受影响行为 ' || sql%bulk_rowcount(i)||' 行 ! '|| sql%rowcount);
end loop;
END;

---结果:

 insert --------------19
GFWD insert 受影响行为 1 行 !
GOPTION insert 受影响行为 1 行 !
NCD insert 受影响行为 1 行 !
GLS insert 受影响行为 1 行 !
IBO insert 受影响行为 1 行 !
REPO insert 受影响行为 1 行 !
OBPO insert 受影响行为 1 行 !
BSD insert 受影响行为 1 行 !
DEPO insert 受影响行为 1 行 !
IRS insert 受影响行为 1 行 !
FXSWAP insert 受影响行为 1 行 !
FRA insert 受影响行为 1 行 !
IBL insert 受影响行为 1 行 !
FXFWD insert 受影响行为 1 行 !
CCS insert 受影响行为 1 行 !
FXOPTION insert 受影响行为 1 行 !
GSWAP insert 受影响行为 1 行 !
BSDC insert 受影响行为 1 行 !
CI insert 受影响行为 1 行 !
update --------------19
GFWD update 受影响行为 1 行 ! 19
GOPTION update 受影响行为 1 行 ! 19
NCD update 受影响行为 1 行 ! 19
GLS update 受影响行为 1 行 ! 19
IBO update 受影响行为 1 行 ! 19
REPO update 受影响行为 1 行 ! 19
OBPO update 受影响行为 1 行 ! 19
BSD update 受影响行为 1 行 ! 19
DEPO update 受影响行为 1 行 ! 19
IRS update 受影响行为 1 行 ! 19
FXSWAP update 受影响行为 1 行 ! 19
FRA update 受影响行为 1 行 ! 19
IBL update 受影响行为 1 行 ! 19
FXFWD update 受影响行为 1 行 ! 19
CCS update 受影响行为 1 行 ! 19
FXOPTION update 受影响行为 1 行 ! 19
GSWAP update 受影响行为 1 行 ! 19
BSDC update 受影响行为 1 行 ! 19
CI update 受影响行为 1 行 ! 19

--sql%rowcount  && cursor%rowcount ;

 declare
cursor cur_stp is
select s.productcode pcode from sys_product s;
TID varchar2(100);
begin
open cur_stp;
dbms_output.put_Line('0_cur_stp%rowcount='||cur_stp%rowcount);
loop
fetch cur_stp
into tid;
--注意这里没有换行;
dbms_output.put(cur_stp%rowcount||' '); --'0~19'
exit when cur_stp%notfound;
end loop;
--放到游标里面和外面的区别;
dbms_output.put_Line('sql%rowcount=' || sql%rowcount);
dbms_output.put_Line('1_cur_stp%rowcount=' || cur_stp%rowcount);
close cur_stp; for i in cur_stp loop
dbms_output.put_Line(cur_stp%rowcount || '--' || i.pcode);
end loop;
--放到底部的话会 抛错 :无效的游标; dbms_output.put_Line(cur_stp%rowcount);
end;

--结果:

 0_cur_stp%rowcount=0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 19 sql%rowcount=
1_cur_stp%rowcount=19
1--GFWD
2--GOPTION
3--NCD
4--GLS
5--IBO
6--REPO
7--OBPO
8--BSD
9--DEPO
10--IRS
11--FXSWAP
12--FRA
13--IBL
14--FXFWD
15--CCS
16--FXOPTION
17--GSWAP
18--BSDC
19--CI

sql%bulk_rowcount && sql%rowcount 的使用的更多相关文章

  1. SQL Server中@@ROWCOUNT的用法

    SQL Server中@@ROWCOUNT返回受上一语句影响的行数,返回值类型为 int 整型. 如果行数大于 20 亿,则需要使用 ROWCOUNT_BIG. @@ROWCOUNT和@@ERROR变 ...

  2. [转载]Oracle数据库 sql%found,sql%notfound,sql%rowcount

    sql%found,sql%notfound,sql%rowcount 在执行DML(insert,update,delete)语句时,可以用到以下三个隐式游标(游标是维护查询结果的内存中的一个区域, ...

  3. sql%found sql%notfound sql%rowcount sql%isopen

    原文引入:http://blog.csdn.net/mh942408056/article/details/6949325 sql%found sql%notfound sql%rowcount sq ...

  4. SQL PL/SQL语法手册

    SQL  PL/SQL语法手册 目   录 第一部分  SQL语法部分 3 一. CREATE TABLE 语句 3 二. CREATE SEQUENCE语句 5 三. CREATE VIEW语句 6 ...

  5. SQL Server SQL性能优化之--通过拆分SQL提高执行效率,以及性能高低背后的原因

    复杂SQL拆分优化 拆分SQL是性能优化一种非常有效的方法之一, 具体就是将复杂的SQL按照一定的逻辑逐步分解成简单的SQL,借助临时表,最后执行一个等价的逻辑,已达到高效执行的目的 一直想写一遍通过 ...

  6. SQL Server SQL分页查询

    SQL Server SQL分页查询的几种方式 目录 0.    序言 1.    TOP…NOT IN… 2.    ROW_NUMBER() 3.    OFFSET…FETCH 4.    执行 ...

  7. pl/sql和sql的区别

    源地址:https://zhidao.baidu.com/question/187511430.html 1 sql(数据定义语言) 和PL/Sql的区别:答:SQL是结构化查询语言,比较接近自然语言 ...

  8. 对SQL Server SQL语句进行优化的10个原则

    1.使用索引来更快地遍历表. 缺省情况下建立的索引是非群集索引,但有时它并不是最佳的.在非群集索引下,数据在物理上随机存放在数据页上.合理的索引设计要建立在对各种查询的分析和预测上.一般来说:①.有大 ...

  9. PL/SQL --> 动态SQL调用包中函数或过程

    动态SQL主要是用于针对不同的条件或查询任务来生成不同的SQL语句.最常用的方法是直接使用EXECUTE IMMEDIATE来执行动态SQL语句字符串或字符串变量.但是对于系统自定义的包或用户自定的包 ...

随机推荐

  1. PostgreSQL PITR实验

    磨砺技术珠矶,践行数据之道,追求卓越价值 回到上一级页面: PostgreSQL基础知识与基本操作索引页     回到顶级页面:PostgreSQL索引页 看PostgreSQL中与PITR相关的设定 ...

  2. 使用bootstrap-select控件 搜索栏键入关键字动态获取后台数据

    bootstrap-select开源地址:https://github.com/silviomoreto/bootstrap-select bootstrap-select使用示例:http://si ...

  3. 【转载】COM 组件设计与应用(六)——用 ATL 写第一个组件

    原文:http://vckbase.com/index.php/wv/1216.html 一.前言 1.与 <COM 组件设计与应用(五)>的内容基本一致.但本回讲解的是在 vc.net ...

  4. 前端- html -总结

    html概述 head标签 title 显示网站的标题 meta 提供有关页面的原信息 link 链接css资源文件.网站图标 style 定义内部样式表 script 链接脚本js文件 body标签 ...

  5. DELL R710使用4T硬盘亮黄灯

    事件背景 公司DELL R710的物理机上面运行的SQL SERVER数据库,因存储空间不足需要扩充空间.现系统盘(300G SAS 6Gbps 15K*2)RAID 1,数据盘(500G SAS 6 ...

  6. matlab GUI工作原理

    例如,用GUIDE创建名为ceshi的GUI程序,其m文件的主函数有如下形式.那么,打开该GUI时,它到底是怎么运行的呢?以下略作小结,欢迎大家补充 function varargout = cesh ...

  7. Distributed3:SQL Server 分布式数据库性能测试

    我在三台安装SQL Server 2012的服务器上搭建分布式数据库,把产品环境中一年近1.4亿条数据大致均匀地存储在这三台服务器中,每台Server 存储4个月的数据,物理机的系统配置基本相同:内存 ...

  8. loadrunner使用过程中的问题记录

    一.录制时选错应用类型,导致提示“loadrunner sockets proxy auto-starter mercury interactive corp.(2002)” 解决办法:重新选择正确的 ...

  9. Python学习之路:NumPy进阶

    import numpy as np; #创建数组的四种办法 ##可以传入任何类数组 a = np.array([0,1,2,3,4]); b = np.array((0,1,2,3,4)); c = ...

  10. linux centos7 nginx 安装部署和配置

    1/什么是NginxNginx("enginex")是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器,在高连接并发的情况下Nginx是Apac ...