1.批量绑定是指执行单次SQL操作能传递所有集合元素的数据,可以极大的加快数据处理速度,提高程序的性能,它是使用Bulk Collect子句和ForALL子句来完成的。
2.ForAll:该子句只适用于执行批量的DML操作,只能修饰一条语句,它包括3种语法:
a.
ForAll index in lower_bound..upper_bound
sql_statement;
例如:
create table my_demo(
mid number(6) primary key,
mname varchar2(50)
);
declare
type my_index_table1 is table of my_demo.mid%type index by binary_integer;
type my_index_table2 is table of my_demo.mname%type index by binary_integer;
my_id my_index_table1;
my_name my_index_table2;
start_time number(10);
end_time number(10);
begin
for i in 1..1000 loop
my_id(i):=i;
my_name(i):=to_char(i)||'NAME';
end loop;
start_time:=dbms_utility.get_time;
forall i in 1..1000
insert into My_DEMO values(my_id(i),my_name(i));
end_time:=dbms_utility.get_time;
dbms_output.put_line(end_time-start_time);
end;
b.
ForAll index in indices of collection
[Between lower_bound.and. upper.bound]
sql_statement;(和迭代器一样,遍历集合)
例如:
declare
type id_table_type is table of demo%rowtype index by binary_integer;
id_table id_table_type;
type index_table_type is table of Pls_Integer index by binary_integer;
index_table index_table_type;
begin
select object_id,object_name bulk collect into id_table from all_objects where rownum<=10;
index_table(1):=1;
index_table(2):=2;
index_table(4):=6;
index_table(6):=8;
index_table(8):=10;
forall i in indices of index_table--其中index_table中是1,2,4,6,8
insert into demo(did) values(id_table(i).did);--id_table(1,2,4,6,8)
end;
c.
ForAll index in values of index_collection
sql_statement;(遍历集合里面的值)
例如:
declare
type id_table_type is table of demo%rowtype index by binary_integer;
id_table id_table_type;
type index_table_type is table of PLS_Integer index by binary_integer;
index_table index_table_type;
begin
select object_id,object_name bulk collect into id_table from all_objects where rownum<=10;
index_table(1):=1;
index_table(2):=2;
index_table(4):=6;
index_table(6):=8;
index_table(8):=10;
forall i in values of index_table--其中index_table中的值是1,2,6,8,10
insert into demo(did) values(id_table(i).did);--id_table(1,2,6,8,10)
end;
3.Bulk Collect:该子句用于取得批量数据,只能用于Select、Fetch和DML返回子句中。
declare
type eaa is record(
empno scott.emp.empno%type,
ename scott.emp.ename%type,
sal scott.emp.sal%type
);
type emp_table_type is table of scott.emp%rowtype
index by binary_integer;
emp_table emp_table_type;
type aa is table of scott.emp%rowtype;
a aa;
type bb is varray(1000) of scott.emp%rowtype;
b bb;
begin
select * bulk collect into emp_table from scott.emp;
for i in 1..emp_table.count loop
dbms_output.put_line(emp_table(i).ename);
end loop;
dbms_output.new_line;
select * bulk collect into b from scott.emp;
for i in 1..b.count loop
dbms_output.put_line(b(i).ename);
end loop;
end;
分享到:
相关推荐
关于Oracle FORALL用法的小结
1.在过去一年,小编写过一个批量上传图片的例子,那个例子是基于百度编辑器改造的,用起来必须依赖百度编辑器,所以小编就又弄了一个,就是今天要介绍的了,uploadify上传的了前端用flash,javascript编写,后端兼容...
使用复合数据类型 8.1 PL/SQL记录 8.1.1 定义PL/SQL记录 8.1.2 使用PL/SQL记录 8.2 PL/SQL集合 8.2.1...批量绑定 8.3.1 FORALL语句 8.3.2 BULKCOLLECT子句 8.4 习题 第9章...
项目管理员可以使用QC的Excel插件工具来执行需求的批量导入,进行导入之前请先确认已经访问过MQC主页,并安装了QCMSExcelAddin.exe插件。 插件下载地址: http://updates.merc-int.com/qual ... /msexcel/index.html...
允许你绑定一个在DOM文档载入完成后执行的函数。这个函数的作用如同$(document).ready()一样,只不过用这个函数时,需要把页面中所有需要在 DOM 加载完成时执行的$()操作符都包装到其中来。从技术上来说,这个函数是...
Java 源码包 Applet钢琴模拟程序java源码 2个目标文件,提供基本的音乐编辑功能。编辑音乐软件的朋友,这款实例会对你有所帮助。 Calendar万年历 1个目标文件 EJB 模拟银行ATM流程及操作源代码 ...
百度云盘分享 简介 笔者当初为了学习JAVA,收集了很多经典源码,源码难易程度分为初级、中级、高级等,详情看源码列表,需要的可以直接下载! 这些源码反映了那时那景笔者对未来的盲目,对代码的热情、执着,对...