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
本文地址:http://com.8s8s.com/it/it20008.htm