根据oracle数据库中的主键确定重复的数据有哪些
select XMAN_ID, EVENT, CATALOG_CODE, SERIAL(主键字段名) from sehr_xman_ehr_2(表名)GROUP BY
XMAN_ID, EVENT, CATALOG_CODE, SERIAL(主键字段名)
having count(*)>1;
查询到有重复的数据就可以按照字段删除了,先把按照主键字段查出来数据,备份到一张临时表中,
CREATE TABLE sehr_2(临时表名) AS
(select XMAN_ID, EVENT, CATALOG_CODE, SERIAL(主键字段) from sehr_xman_ehr_2(原表名) group by
XMAN_ID, EVENT, CATALOG_CODE, SERIAL(主键字段)
having count(1) > 1)
备份数据后就可以根据备份的数据删除重复表中的数据了
delete from test_delete(表名) t1 where exists(select 1 from test_de(临时表) t2 where
t2.id_no=t1.id_no and t2.na = t1.na and
t2.code = t1.code and t2.age = t1.age)
and rowid not in (select min(rowid) from test_delete(表名) group by id_no,na,code,age(主搜索字段名) having count(*)>1)
//根据字段条件进行筛选,和流行rowid最小的那条
亲测有效,删除重复数据的速度很快
最后在执行,drop table test_de(临时表)删除临时表