oracle 简单去重过程

Oracle利用rowid删除表中重复记录spa

 

先看表myemp索引

 

 

查出有重复数据的记录it

 

 

查出没有重复数据的记录io

 

 

查出不重复的记录class

 

 

或者效率

select * from myemp e where rowid = (select max(rowid) from myemp e2 where e.userid = e2.userid and e.username = e2.username and e.salary = e2.salary)select

 

 

如何删除重复数据exception

一、  当有大量重复数据存在而且在列userid,username,salary上有索引的状况下方法

delete myemp where rowid not in (select max(rowid) from myemp group by userid,username,salary);im

二、 适用于少许重复数据的状况(当有大量数据时,效率很低)

delete myemp e where rowid <> (select max(rowid) from myemp e2 where e.userid = e2.userid and e.username = e2.username and e.salary = e2.salary);

三、 exception方法,适合大量重复数据的状况

首先创建exception

 

而后添加约束,将错误记录到表exceptions

 

创建重复数据临时表

 

删除有重复的全部数据

 

将临时表中的非重复数据从新插入原表

相关文章
相关标签/搜索