Oracle中游標使用效率比較

2021-06-18 13:00:01 字數 1061 閱讀 7067

鳴謝:

擴充套件:對300萬一張表資料,用游標進行迴圈,不同寫法的效率比較

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;  www.2cto.com

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秒,看樣子這種最快

oracle 游標使用

create or replace function errortyperead return varchar2 is result varchar2 3000 type cursor type is ref cursor tempname varchar2 100 cursor testcur i...

oracle游標使用

在進行pl sql程式設計時,我們都會使用游標,游標有兩種,一種是顯式游標,使用類似如下方式 open 游標 loop fetch into exit when notfound end loop close 游標 另一種是隱式游標,使用類似如下 for 游標變數 in 游標 loop 賦值變數 游...

Oracle游標使用

一,什麼是游標 遍歷查詢結果集的一種機制。二,為什麼避免使用游標 盡量避免使用游標,因為游標的效率較差 如果使用了游標,就要盡量避免在游標迴圈中再進行表連線的操作。三,使用游標的步驟 靜態游標 1,宣告一些變數,用來儲存游標遍歷過程的臨時資料 2,宣告游標,並且指定查詢 3,開啟游標 4,從游標中獲...