1.大量繫結是指執行單次SQL操作能傳遞所有集合元素的資料,可以極大的加快資料處理速度,提高程式的效能,它是使用Bulk Collect子句和ForALL子句來完成的。
2.ForAll:該子句只適用於執行批量的DML操作,只能修飾一條語句,它包括3種文法:
a.ForAll index in lower_bound..upper_boundsql_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_collectionsql_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;