Oracle表中重复记录高效删除法


 以前的一篇删除重复记录的虽然还不错 但是在我遇到重量级的大表时还是显的力不从心,不小心想到一种新的方法

  思路1、保存不重复的记录

  2、保存重复记录中的一个rowid

  //3、删除原表中rowid不为步骤2中rowid的记录 ,留下重复数据中的一条

  3.找出记录中rowid为步骤2中rowid的记录

  4 、1和3数据连接就是所要的数据了

  具体操作例子

  第一步:

  SQL> create table xxfgs_sig as (select imeid imeid,max(dn) dn,max(xlh) xlh,max(pro_name) pro_name,max(area_name) area_na

  me,max(brand) brand,max(m_type) m_type from xxfgs group by imeid having count(*)<2);

  第二步:

  SQL> create table xxfgs_row as (select max(rowid) rowdata,imeid from xxfgs group by imeid having count(*)>1);

  //第三步:////可以考虑给meid建索引

  //SQL>delete from xxfgs where rowid not in (select rowdata from xxfgs_row);

  //或者

  //SQL>delete from xxfgs a where a.rowid <>(select rowdata from xxgs_row b where a.meid=b.meid);

  第三步:

  SQL>create table xxfgs_dub as (select * from xxfgs where rowid in (select rowdata from xxfgs_row));

  第四步:

  SQL>insert into xxfgs_sig select * from xxfgs_dub;

 以前的一篇删除重复记录的虽然还不错 但是在我遇到重量级的大表时还是显的力不从心,不小心想到一种新的方法

  思路1、保存不重复的记录

  2、保存重复记录中的一个rowid

  //3、删除原表中rowid不为步骤2中rowid的记录 ,留下重复数据中的一条

  3.找出记录中rowid为步骤2中rowid的记录

  4 、1和3数据连接就是所要的数据了

  具体操作例子

  第一步:

  SQL> create table xxfgs_sig as (select imeid imeid,max(dn) dn,max(xlh) xlh,max(pro_name) pro_name,max(area_name) area_na

  me,max(brand) brand,max(m_type) m_type from xxfgs group by imeid having count(*)<2);

  第二步:

  SQL> create table xxfgs_row as (select max(rowid) rowdata,imeid from xxfgs group by imeid having count(*)>1);

  //第三步:////可以考虑给meid建索引

  //SQL>delete from xxfgs where rowid not in (select rowdata from xxfgs_row);

  //或者

  //SQL>delete from xxfgs a where a.rowid <>(select rowdata from xxgs_row b where a.meid=b.meid);

  第三步:

  SQL>create table xxfgs_dub as (select * from xxfgs where rowid in (select rowdata from xxfgs_row));

  第四步:

  SQL>insert into xxfgs_sig select * from xxfgs_dub;


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3