ora-02437错误解决方法总结--表数据去重

来源:互联网 发布:dnf剑宗技能数据介绍 编辑:程序博客网 时间:2024/06/04 18:19

ORA-02437错误:创建表时没有添加主键,当表中已经存在很多重复数据时,再添加主键就会报这个错误。所以,设计表的时候一定要注意!

下面是这个错误的解决办法,先找出表中重复的数据,然后删除相同数据rowid最小的那一列

select * from material_tablewhere unid in (select   unid from material_table group by unid having count(unid) > 1)

这里的unid 是主键列,通过主键进行分组查找出记录大于1条的数据。

找到重复数据后进行删除

delete from material_table where unid in (select unid from material_table group by  unid having count(unid) > 1) and rowid not in (select min(rowid) from material_table  group by unid having count(unid)>1)


原创粉丝点击