使用Bulk Binding大量繫結的模式高效處理ORACLE大量資料

來源:互聯網
上載者:User

標籤:cursor   integer   批量提交   參考   class   state   rom   archive   UI   

       用大量繫結(bulk binding)的方式。當迴圈執行一個綁定變數的sql語句時候,在PL/SQL 和SQL引擎(engines)中,會發生大量的環境切換(context switches)。使用bulk binding,能將資料批量的從plsql引擎傳到sql引擎,從而減少環境切換過程,提升效率。

       在Oracle使用過程中經常會遇到需要插入大量資料的情況,這種情況下就可以使用Bulk Binding插入資料。

      參考資料:Oracle逐行提交、批量提交及極限提速方法

        ORACLE Bulk Binding大量繫結

       Oracle PL/SQL 最佳化與調整 -- Bulk 說明

 

參考代碼:

DECLARE  -- Local variables here  l_date_f DATE;  l_date_t DATE;  TYPE t_event_id IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;  l_event_id t_event_id;  CURSOR c_data(p_date_f DATE, p_date_t DATE) IS    SELECT xe.event_id,           xe.event_date,           xe.application_id,           xe.process_status_code      FROM xla_events xe     WHERE xe.application_id = 707       AND xe.process_status_code <> ‘P‘       AND xe.event_date > p_date_f       AND xe.event_date <= p_date_t;  TYPE t_tab IS TABLE OF c_data%ROWTYPE;  l_event t_tab;BEGIN  -- Test statements here  l_date_f := to_date(‘2008/01/01‘, ‘yyyy/dd‘);  l_date_t := to_date(‘2017/05/31‘, ‘yyyy/dd‘);  FOR i IN 1 .. (l_date_t - l_date_f) LOOP    --dbms_output.put_line(‘l_date_f:‘||to_char(l_date_f+i-1,‘yyyy/dd‘));    --dbms_output.put_line(‘l_date_t:‘||to_char(l_date_f+i,‘yyyy/dd‘));      OPEN c_data(l_date_f + i - 1, l_date_f + i);    LOOP      FETCH c_data BULK COLLECT        INTO l_event LIMIT 10000;      --dbms_output.put_line(l_event.count);      EXIT WHEN l_event.count = 0;      FORALL j IN 1 .. l_event.count        INSERT INTO xla_events_bak          (application_id,           event_id,           event_date,           event_status_code,           process_status_code)        VALUES          (l_event(j).application_id,           l_event(j).event_id,           l_event(j).event_date,           l_event(j).event_status_code,           l_event(j).process_status_code);          FORALL j IN 1 .. l_event.count        UPDATE xla_events xe           SET xe.process_status_code = ‘P‘, xe.event_status_code = ‘P‘         WHERE xe.event_id = l_event(j).event_id           AND xe.application_id = l_event(j).application_id;          COMMIT;    END LOOP;    CLOSE c_data;  END LOOP;END;

 

        

使用Bulk Binding大量繫結的模式高效處理ORACLE大量資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.