分别用了没有绑定变量的INSERT语句、有绑定变量的INSERT语句,两种方法都用了两小时以上还没跑完,有朋友说用oracle数据泵,看了网上资料,这是个导入导出功能呀,我是在一空表插入一亿条数据,觉得不适合呀
求高手指点
用绑定变量
declare
 v_sql varchar2(4000);
  begin
    for i in 1 .. 1234567890 loop
      v_sql := 'insert into use_bind_lyh(id) values(:x)';
      execute immediate v_sql
        using i;
      commit;
    end loop;
  end;不用绑定变量
declare
    v_sql varchar2(4000);
  begin
    for i in 1 .. 1234567890 loop
      v_sql := 'insert into use_bind_lyh2(id) values (' || i || ')';
      execute immediate v_sql;
      commit;
    end loop;
  end ;

解决方案 »

  1.   

    试一下,改“commit;”为:
    if mod(i,1000)=0 then
      commit;
    end if;
    也就是批量提交,不要一条一条的提交。
    其中的1000可以测试看看是多少比较快,我插入了123456条记录,感觉100、1000、10000差别不大。
      

  2.   

    这个试验是要比较是否绑定变量带来的性能差异,但实际上这个差异较小,因此才把执行次数增加来放大,且要降低其他的干扰因素带来的影响
    因此,这里要把表里的索引删掉
    且确定数据库中cursor_sharing参数此时的值是exact
    执行次数你这里是10多亿,太多了,先采用100万,差异太小,再增加量级
      

  3.   

    1、提交次数过贫
    2、删除索引,插入完毕后重建3、试试这种方式inset into t values(1);
    for i in 0 ..33 loop
    insert into t select 序列.next from t;
    end loop;
      

  4.   

    一亿条在插入时不要每一条都commit,用批量插入,删除所有的索引,数据插入完成在建立索引。
      

  5.   


    -- 我这里灌了 1亿条记录,你大概参考一下时间;
    SQL> create table x(x int) ;
    Table created
    Executed in 0.069 seconds
    SQL> begin
      2      insert into x select rownum from dual connect by rownum <= 10000 ;
      3      for x in 1..9999 loop
      4          insert into /*+ append */x select * from x where rownum <= 10000;
      5          commit ;
      6      end loop ;
      7  end ;
      8  /
    PL/SQL procedure successfully completed
    Executed in 74.242 seconds
    SQL> select count(*) from x ;
      COUNT(*)
    ----------
     100000000
    Executed in 7.061 seconds
    SQL> drop table x purge ;
    Table dropped
    Executed in 0.174 secondsSQL>