`
wattone
  • 浏览: 39987 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Oracle中删除重复记录行

阅读更多
主要是利用oracle中记录行的rowid唯一。

去除重复记录(注意多次执行直到影响记录为0行)
delete from WBH_TEMP2 where terminal_id in (
select terminal_id from WBH_TEMP2 group by terminal_id having count(*)>1)
and rowid in (select max(rowid) from WBH_TEMP2 group by terminal_id having count(*)>1)


——————————————————————————————————————————
与上面一条等价,这条执行一次即可去除重复记录
delete from WBH_TEMP2 where terminal_id in (
select terminal_id from WBH_TEMP2 group by terminal_id having count(*)>1)
and rowid not in (select min(rowid) from WBH_TEMP2 group by terminal_id having count(*)>1)


——————————————————————————————————————————
大量数据的时候建议用CTAS
create table WBH_TEMP3 as select terminal_id from WBH_TEMP2 group by terminal_id

这样子WBH_TEMP3中就是去除重复的记录了。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics