要insert int a  1000w 条数据。
我想分批插入 , 比如每次插入5000条。
应该用什么类型的变量来保存啊。比如  b 表  ID   NUMBER 类型
a 表 ID  NUMBER 类型想把B的数据插入到A  分批 应该怎么处理

解决方案 »

  1.   

    declare
        cnt number:=0;
    begin
        insert into a select * from b;
        cnt:=cnt+1;
        if cnt>5000 then
           commit;
        end if;
    exception 
        when others then
            rollback;
    end;
      

  2.   

    declare
      cnt number:=0;
      cursor cur is select * from b;
      rs cur%rowtype;
    begin
      open cur;
      loop
         fetch cur in rs 
         insert into a values(rs.id);
         cnt:=cnt+1;
         if cnt>5000 then
            commit;
         end if;
      end loop;
    exception  
      when others then
      rollback;
    end;
      

  3.   

    回复楼上的 1QW 的表用游标是不是有点那个啥了? 
    你要插入的数据表是什么样子的?
    有没有 分区 或者索引之类的东西 可以考虑 用分区 或索引 添加的时候 /*+append*/