1、显示游标
declare
cursor cur_2 is select a.cust_name from ea_cust.cust_info a;
cust_id varchar2(100);
begin
open cur_2;
loop
fetch cur_2 into cust_id;
exit when cur_2%notfound;
NULL;
end loop;
close cur_2;
end;
--耗时48秒
2、隐式游标
declare
begin
for cur_ in (select c.cust_name from ea_cust.cust_info c) loop
NULL;
end loop;
end;
--耗时16秒
3、bulk collect into + cursor
declare
cursor cur_3 is select a.cust_name from ea_cust.cust_info a;
type t_table is table of varchar2(100);
c_table t_table;
to_cust_id varchar2(100);
begin
open cur_3;
loop
fetch cur_3 bulk collect into c_table limit 100;
exit when c_table.count = 0;
for i in c_table.first..c_table.last loop
null;
end loop;
end loop;
commit;
end;
--耗时13秒,看样子这种最快
本文通过三种不同的游标实现方式:显示游标、隐式游标及BULK COLLECT INTO结合游标的使用,在Oracle数据库中进行性能测试。结果显示,BULK COLLECT INTO结合游标的方案在处理大量数据时表现最优,仅耗时13秒。
4万+

被折叠的 条评论
为什么被折叠?



