C/C++教程

Oracle 数据库表删除重复数据

本文主要是介绍Oracle 数据库表删除重复数据,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

删除重复数据并保留一条

方法一

  • 1、建立临时表,记录重复的数据
create table 临时表  as 
select a.字段1,a.字段2,max(a.rowid) as dataid 
from 原表 a 
group by a.字段1,a.字段2;
  • 2、删除重复数据并提交
delete from 原表 a 
where a.rowid != (select b.dataid 
                  from 临时表 b 
                  where a.字段1 = b.字段1 and a.字段2 = b.字段2);

commit;

方法二

 delete from 表名 t
 where t.rowid not in
       (select max(rowid) from 表名 t1 group by t1.字段1, t1.字段2);

这篇关于Oracle 数据库表删除重复数据的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!