(1) DELETE FROM table_name A WHERE ROWID > (
       SELECT min(rowid) FROM table_name B
        WHERE A.key_values = B.key_values);
(2)create table table2 as select distinct * from table1;
     drop table1;
     rename table2 to table1;
(3) Delete from mytable where rowid not in(
       select max(rowid) from mytable
       group by column_name );
(4)delete from mytable t1
      where  exists (select 'x' from my_table t2
                   where t2.key_value1 = t1.key_value1
                     and t2.key_value2 = t1.key_value2
                     ...
                     and t2.rowid > t1.rowid);
除了这4种方法,还有更好的吗?
对了这四种方法那个更好?

解决方案 »

  1.   

    没有不同的意见吗?
     jaguarcts(jaguarcts) 
    请说说你的理由?
      

  2.   

    只能通过rownum来删除重复记录了
      

  3.   

    1:  sqlldr 可以把重复的数据剔出来
    2: 可以剔除重复数据后再建立唯一索引,这也不是很麻烦,不就几百万条记录么?不要delete而用重新建表,
    3:如果你的唯一索引可以允许以前的数据存在重复 的,只是今后不允许插入重复数据,可以建立约束的时候指定约束状态允许这种情况存在,但是会否对你的应用构成影响?所以建议:
    alter session set sort_area_size = 10240000;
    根据字段创建索引
    analyze table xxx compute statistics;
     create table t as select *  from xxx a
    where rowid = (select max(rowid) from xxx b where b.col1 = a.col1);
    truncate table xxx;
    insert into xxx select ... from t;
    然后加唯一约束
      

  4.   

    truncate table xxx;
    insert into xxx select ... from t;8i中可以换做:drop table xxx;
    rename t to xxx;
      

  5.   

    哦,非常感谢 biti_rainy(biti_rainy) 指点
    没有其他意见吗?