我用insert into 表名 select 源数据
导入数据,由于源数据很大。我想每导入一行提交一次,而不是系统默认的全部完成后提交一次。
我应该怎么写这个SQL

解决方案 »

  1.   

    频繁的提交也不好,分批提交吧,比如1万条提交一次.
    表里找出一个可以分段的字段来,如果有顺序的id或时间字段.
    insert into tb_new select * from tb where id <10000;
    commit;
    insert into tb_new select * from tb where id between 10000 and 20000;
    commit;
    ....
      

  2.   

    每次都commit对IO影响太大。
    对1555错误,可以考虑用临时表方式处理,create table .. as select 快于insert into ..select。
    先create table tmp_t nologging as select 数据源,
    再用过程分批提交:
    declare
    i number:=0;
    begin
    for cur_a in(select .. from tmp_t) loop
    insert /*+ append */ into t values(cur_a.col1,cur_a.col2,...);
    i:=i+1;
    --1000行commit一次
    if mod(i,1000)=0 then
    commit;
    end if;
    end loop;
    end;
    /
      

  3.   

    你的意思是先create 一个临时表,然后由临时表导入数据,在drop 临时表?
      

  4.   

    create table .. as select 能够自动建索引吗?我表中数据近千万条
      

  5.   

    慢了一步,但还是贴出来:
    /--可以直接建临时表,不需要给temp_table做定义
    create table temp_table as (select * from tableB  where 1=1 and sql_condition);
    create index t_temp on temp_table(...);/--将temp_table内容一次插入至主表中
    insert into tableA as (select * from temp_table);