Oracle数据库重复数据删除的三种情况

时间:2008-09-14 12:09:41  来源:互联网  作者|记者:不详  浏览:3  大小:【】【】【
捌度空间导读:在对数据库进行操作过程中我们可能会遇到这种情况,表中的数据可能重复出现,使我们对数据库的操作过程 ...
在对数据库进行操作过程中我们可能会遇到这种情况,表中的数据可能重复出现,使我们对数据库的操作过程中带来很多的不便,那么怎么删除这些重复没有用的数据呢?

一、删除部分字段重复数据

 select a.rowid,a.* from 表名 a   where a.rowid !=   (   select max(b.rowid) from 表名 b   where a.字段1 = b.字段1 and   a.字段2 = b.字段2   )

  delete from 表名 a   where a.rowid !=   (   select max(b.rowid) from 表名 b   where a.字段1 = b.字段1 and   a.字段2 = b.字段2   )

  create table 临时表 as   select a.字段1,a.字段2,MAX(a.ROWID) dataid from 正式表 a GROUP BY a.字段1,a.字段2;   delete from 表名 a   where a.rowid !=   (   select b.dataid from 临时表 b   where a.字段1 = b.字段1 and   a.字段2 = b.字段2   );   commit;

  CREATE TABLE 临时表 AS (select distinct * from 表名);  truncate table 正式表;  /pre>                        

  INSERT INTO t_table_bak   select distinct * from t_table;



引用地址:

相关文章