Oracle数据库删除表中重复记录的常见方法

    技术2022-05-20  42

     

    方法一:

    delete from tb_channel a where a.rowid in

    (select max(b.rowid) from tb_channle b

    where a.policyno=b.policyno and a.classcode=b.classcode);

    ——这一办法在数据记录超过10万时一般都会变得很慢。

    方法二:

    --建立临时表,--清空原表,--插回原表,如下例:

    create table temp_emp as (select distinct * from employee) ;

    truncate table employee;

    insert into employee select * from temp_emp;

    ——这一办法适用于较大的表的情况。因为是块操作,对应于大表效率会好很多

    方法三:

    --建立新表,--去重复放入,--删除原表,如下例:

    select distinct * into new_table from old_table

    order by 主 键

    drop table old_table

    exec sp_rename new_table,old_table;

    ——这一办法适用于较大的表的情况。因为是块操作,对应于大表效率会好很多


    最新回复(0)