Chinaunix首页 | 论坛 | 博客
  • 博客访问: 729874
  • 博文数量: 95
  • 博客积分: 1754
  • 博客等级: 上尉
  • 技术积分: 1607
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-12 10:06
文章分类

全部博文(95)

文章存档

2015年(3)

2013年(15)

2012年(77)

分类: Oracle

2012-05-14 11:46:24

删除ORACLE重复的数据常用方式,根据rowid来编写SQL脚本:
 
delete from t_web
 where rowid in (select a.rowid, a.web_name
                   from t_web a, t_web b
                  where a.rowid > b.rowid
                    and a.web_name = b.web_name);
                   
delete from t_web a
 where rowid not in
       (select max(b.rowid) from t_web b  where a.web_name = b.web_name )
      
delete from t_web
where rowid not in (select max(rowid) from t_web a group by a.web_name);                       
 

delete from tbl
 where (col1, col2) in
       (select col1, col2 from tblgroup bycol1, col2havingcount(*) > 1)
   and rowidnotin(selectnin(rowid) fromtblgroup bycol1,
                  col2havingcount(*) > 1);
阅读(816) | 评论(1) | 转发(1) |
给主人留下些什么吧!~~

7大爷2012-05-14 22:07:11

呵呵,很实用的东西,分享了!