Oracle游標進行循環效率比較


對300萬一張表數據,用游標進行循環,不同寫法的效率比較

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

Oracle

對300萬一張表數據,用游標進行循環,不同寫法的效率比較
摘要: 對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_2 in (select c.c... 閱讀全文

posted @ 2013-01-06 18:12 Code changes life 閱讀(563) | 評論 (0) 編輯

oracle行列轉換
摘要: Oracle 行列轉換1、固定列數的行列轉換如student subject grade--------- ---------- --------student1 語文 80student1 數學 70student1 英語 60student2 語文 90student2 數學 80student2 英語 100……轉換為語文 數學 英語student1 80 70 60student2 90 80 100……語句如下:select student,sum(decode(subject,'語文', grade,null)) "語文",sum(decode( 閱讀全文

posted @ 2013-01-06 16:38 Code changes life 閱讀(334) | 評論 (0) 編輯

數據庫關聯映射建表圖示
摘要: ~總結一下數據庫的 一對多、多對一、一對一、多對多 關系 以及對應的建表方式~關聯映射:一對多/多對一存在最普遍的映射關系,簡單來講就如球員與球隊的關系;一對多:從球隊角度來說一個球隊擁有多個球員 即為一對多多對一:從球員角度來說多個球員屬於一個球隊 即為多對一數據表間一對多關系如下圖:關聯映射:一對一一對一關系就如球隊與球隊所在地址之間的關系,一支球隊僅有一個地址,而一個地址區也僅有一支球隊。數據表間一對一關系的表現有兩種,一種是外鍵關聯,一種是主鍵關聯。圖示如下:一對一外鍵關聯:一對一主鍵關聯:要求兩個表的主鍵必須完全一致,通過兩個表的主鍵建立關聯關系關聯映射:多對多多對多關系也很常見,例 閱讀全文

posted @ 2013-01-04 17:01 Code changes life 閱讀(153) | 評論 (0) 編輯

Oracle中查詢正鎖表的用戶及釋放被鎖的表的方法
摘要: 查詢oracle鎖定的表及殺掉鎖表的進程,注意查看的時候要用sys/sys 管理員的身份登錄1、首先查看鎖定的表太進程:SELECT substr(v$lock.sid,1,4) "SID", serial#, V$SESSION.sid, substr(username,1,12) "UserName", substr(object_name,1,25) "ObjectName", v$lock.type "LockType", www.2cto.com decode(rtrim(substr(lmode,1,4 閱讀全文

posted @ 2012-12-27 14:43 Code changes life 閱讀(1551) | 評論 (0) 編輯

oracle小常識
摘要: 一、oracle時間類型的處理1、用sql語句把時間 2010-10-01 09:28:03插入oracle 的date類型字段insert into 表名(字段名) values (to_date('2010-10-01 09:28:03','yyyy-mm-dd hh24:mi:ss'))2、根據date類型字段查詢select * from 表名 where to_char(date類型字段,'yyyy-mm-dd') between '2012-03-06' and '2012-03-08'二、delete 閱讀全文

posted @ 2012-03-08 09:13 Code changes life 閱讀(106) | 評論 (0) 編輯

分類:  Oracle


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM