提高上百萬行數據insert速度的方法

有兩個結構相同的表table1,table2
將table1插入到table2中:
  
現在採用兩種方法:
1、指定回滾段,回滾段足夠大
set transaction use rollback segment RBS1;
      INSERT INTO table1 NOLOGGING
         SELECT * FROM table2;
     commit;
2、採用定義cursor,每5000或10000條記錄提交一次
declare
    cursor cur_select is
             select t1,t2,t3..... from tabl1;
v_id number;
v_t  table1%rowtype;
  
begin
    open cur_select;
     
    loop
      exit when cur_select%notfound;
      fetch cur_select into v_t.t1,v_t.t2,v_t.t3..... ;
      
      insert into table2
      (t1,t2,t3......)
      values
      (v_t.t1,v_t.t2,v_t.t3..... );
  
      v_id := v_id + 1;
  
      if v_id = 10000 then
        commit;
        v_id := 0;
      end if;
        
    end loop;
  
    commit;  
end;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章