Oracle删除表中的重复数据

匿名 (未验证) 提交于 2019-12-02 23:49:02

Oracle数据库删除表中的重复数据,以两个字段为例,提供两种方法

①、直接delete重复的数据

delete from table_name t1  where  (t1.col1, t1.col2) in (select col1, col2 from table_name group by col1, col2 having count(*) > 1)  and   t1.rowid not in (select min(rowid) from table_name group by col1, col2 having count(*) > 1) ;

②、查询出所有不重复的数据,入到一张中间表中,然后把原表的数据清空,最后把中间表的数据入到原表中

--数据入到中间表中 insert into table_mid_name  select t1.* from table_name t1  where t1.rowid in (select min(rowid) from table_name group by col1, col2 ) ; --清除原表数据 truncate table table_name ; --数据入到原表中 insert into table_name select * from table_mid_name ;

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!