1、现在有TABLEA表,该表中有三百万条数据,要将TABLEA表中数据导到TABLEB中,在插入之前已经将TABLEB表中索引删除,我现在是用merge into 实现的,速度非常慢;
merge into tableb b
  using (select phone
           from tablea) b
  on (a.phone= b.phone)
  when matched then
    update set a.phone = a.phone
  when not matched then
    insert(a.phone) values(b.phone);
2、现在有TABLEC表,该表中有千万条数据,如果UPDATE TABLEC全表的话,用语句:update tableb set readmail = readmail || ',3'很慢;
请教高手我要实现这两个功能,该如何优化以达到速度最快最优效果?
真诚的感谢每一位回复的人,谢谢。

解决方案 »

  1.   

    1中的a,b写得很混乱,看不出哪个是哪个,不知道楼主怎么处理when matched的情况
      

  2.   


    when matched时,不做处理。。
      

  3.   

    2,如果你要在全表的字段上都加两字符的话,语句上没什么更好的办法
    TABLEC中的相关索引先删除再执行
      

  4.   


    merge into tableb b 
      using (select phone 
              from tablea) a --不好意思,之前这里写错了。。
      on (a.phone= b.phone) 
      when matched then 
        update set a.phone = a.phone 
      when not matched then 
        insert(a.phone) values(b.phone);
      

  5.   

    insert into tableb(phone)
    select phone from tablea a
      where not exists(select 1 from tableb where phone=a.phone)
      

  6.   


    tablea,tableb三表都只有一个字段 phone,phone主键
    tablec表有两字段,phone和readmail,phone主键更正下问题2:
    2、现在有TABLEC表,该表中有千万条数据,如果UPDATE TABLEC全表的话,用语句:update tablec set readmail = readmail || ',3'很慢; 
      

  7.   

    1、
    alter table TABLEB nologging;
    insert /*+ APPEND */ into TABLEB SELECT 。。
      

  8.   

    1,关掉tableb 的所有触发器,这个一定要关掉,moving data的时候一定要全部关掉,不然批量操作的时候卡死你Y的。
       alter system tableb disable all triggers;
       执行完毕之后,启动触发器
       alter system tableb enable all triggers;2,除了主键索引之外,tableb表剩余的索引全部删除掉。等执行完毕之后,重建索引(索引重建很快,我的800万数据的表的6个索引重建才花了2分钟而已)3,用批量操作语句,
      insert into tableb select ......;
      update tableb b set b.update tableb set readmail = readmail || ',3';
      

  9.   

    2、TABLEC表结构如何,有多少列?
      

  10.   


    tablec表有两字段,phone和readmail,phone主键 
      

  11.   

    你要更新全表,而且是在字段后加一个字符串',3',那你有没有考虑过非得更新吗?
    能不能在后续的处理过程中稍微处理一下呢,譬如select readmail||',3' from TABLEC 
      

  12.   

    merge into tableb b 
      using tablea a 
      on (a.phone= b.phone) 
      when not matched then 
        insert(b.phone) values(a.phone); 这样不就行了吗
      

  13.   

    1.alter table tableb nologging;
      insert /*+ append */ into tableb.....2.create table test nologging as select readmail||',3' from TABLEC;
      drop table TABLEC;
      alter table test rename to TABLEC;
      

  14.   

    若是9i,必须指定when matched then 
    试试when matched then 
        update set a.phone = a.phone where 1=2
    能否后面跟条件
    set a.phone = a.phone 这个不必要的更新会降低效率
      

  15.   


    9i必须指定when matched then
      

  16.   

    不要使用merge,换成批插入和批更新
      

  17.   


    6楼的就是批插入,以phone建立索引或主健,不要删除