这是我在网上查找的一些方法:
delete from mm5total a where a.rowid!=(select max(rowid) from mm5total b where a.lon=b.lon and a.lat=b.lat and a.moment=b.moment and a.ymd=b.ymd and a.type=b.type)试了一下,运行了一个晚上也没有执行完毕,5555555
后来又想使用这个方法:
select distinct * into #table_name from table_name
delete from table_name
select * into table_name from #table_name
drop table #table_name
我在sqlserver中测试了一下,可以,当时在oracle报错,执行失败.不知道这个方法可不可行啊?是否会快一点?请大家指教.
delete from mm5total a where a.rowid!=(select max(rowid) from mm5total b where a.lon=b.lon and a.lat=b.lat and a.moment=b.moment and a.ymd=b.ymd and a.type=b.type)试了一下,运行了一个晚上也没有执行完毕,5555555
后来又想使用这个方法:
select distinct * into #table_name from table_name
delete from table_name
select * into table_name from #table_name
drop table #table_name
我在sqlserver中测试了一下,可以,当时在oracle报错,执行失败.不知道这个方法可不可行啊?是否会快一点?请大家指教.
解决方案 »
- Oracle存储过程返回结果集,求教
- 如何优化这条select语句!
- 无法初始化ocr
- oracle 10g 12170错误
- ORA-12547:TNS:lost contact错误
- oracle字符串截取查询
- Oracle 存储过程问题
- 关于Oracle
- 紧急求助!!] - with embedded exception: [java.sql.SQLException: IOException during writeClobData: ORA-01691: Lob 段LC.SYS_LOB00
- 一个略难的oracle分组查询问题
- 基础问题,请看看,关于定时执行操作
- 200分求救!! Oracle 无法安装.
方法原理:
1、Oracle中,每一条记录都有一个rowid,rowid在整个数据库中是唯一的,
rowid确定了每条记录是在ORACLE中的哪一个数据文件、块、行上。 2、在重复的记录中,可能所有列的内容都相同,但rowid不会相同,所以只要确定出重复记录中
那些具有最大rowid的就可以了,其余全部删除。 3、以下语句用到了3项技巧:rowid、子查询、别名。 实现方法:
SQL> create table a (
2 bm char(4), --编码
3 mc varchar2(20) --名称
4 )
5 / 表已建立. SQL> insert into a values('1111','1111');
SQL> insert into a values('1112','1111');
SQL> insert into a values('1113','1111');
SQL> insert into a values('1114','1111'); SQL> insert into a select * from a; 插入4个记录. SQL> commit; 完全提交. SQL> select rowid,bm,mc from a; ROWID BM MC
------------------ ---- -------
000000D5.0000.0002 1111 1111
000000D5.0001.0002 1112 1111
000000D5.0002.0002 1113 1111
000000D5.0003.0002 1114 1111
000000D5.0004.0002 1111 1111
000000D5.0005.0002 1112 1111
000000D5.0006.0002 1113 1111
000000D5.0007.0002 1114 1111 查询到8记录. 查出重复记录
SQL> select rowid,bm,mc from a where a.rowid!=(select max(rowid) from a b where a.bm=b.bm and a.mc=b.mc); ROWID BM MC
------------------ ---- --------------------
000000D5.0000.0002 1111 1111
000000D5.0001.0002 1112 1111
000000D5.0002.0002 1113 1111
000000D5.0003.0002 1114 1111 删除重复记录
SQL> delete from a a where a.rowid!=(select max(rowid) from a b where a.bm=b.bm and a.mc=b.mc); 删除4个记录. SQL> select rowid,bm,mc from a; ROWID BM MC
------------------ ---- --------------------
000000D5.0004.0002 1111 1111
000000D5.0005.0002 1112 1111
000000D5.0006.0002 1113 1111
000000D5.0007.0002 1114 1111 根据上贴,即你这样做就应该可以了:
delete from music a1 where a1.rowid!=(select max(rowid) from music a2 where a1.id=a2.id )