求大神帮助。问题是这样的:
我现在需要处理一张有大量重复数据的表(800W条数据大概4,500W重复)。已用group by 和min(rowid)这种方法试验过了。效率太低了。求更快更效率的方法。处理重复数据Oracle效率删除

解决方案 »

  1.   

    --测试数据
    create table ts (a number,b date);
    begin  
    for i in 1..1000000 loop  
      insert into ts values(round(dbms_random.value(1,100)),sysdate);
    end loop;
    commit;
    end;
    --删除重复数据
    create table ts1 as 
    select a, b
      from (select a, b, row_number() over(partition by a order by b) rn from ts)
     where rn = 1;
    drop table ts;
    alter table ts1 rename to ts;比你的下面的这样应该快很多
    delete from ts a
     where a.rowid != (select max(b.rowid) from ts b where a.a = b.a);
      

  2.   

    那可以换个思维  创建一个新表 create table tb2 as 
    select a, b
      from (select a, b, row_number() over(partition by a order by b) rn from tb1)
     where rn = 1;truncate table tb1;insert into tb1 select * from tb2;
      

  3.   

    原表的结构是这样的,一个主键自增,其他数据如果重复的话就是一样的。这样解决的话貌似主键取不到了。主键是通过什么自增的?  如果是sequence 那应该没问题