Oracle中去掉重复的行,用以下方法:
如test表中有如下数据:
现要去掉name中重复的数据,可用如下语句将多余数据删除:
执行后结果:
--方法一:通过group by + rowid,效率低
delete from test t
where trowid not in (select min(rowid) from test group by a, b);
--方法二:通过 create + rename + distinct ,效率高
create table test_tmp as
select distinct from test t;
drop table test;
alter table test_tmp rename to test;
2含大字段(clob等)的表格:
--例子表格:create table test(a number,b clob);--clob 长度小于4000:
select distinct ta,to_char(tb) as b from test t;
--clob 长度大于4000:
select
from test a
where arowid = (select max(browid)
from test b
where ba = aa
and nvl(dbms_lobcompare(bb, ab), 0) = 0);先去重再导入。
删除表中多余的重复记录(多个字段),只留有rowid最小的记录
delete from 表 a
where (aId,aseq) in
(select Id,seq from 表 group by Id,seq having count() > 1)
and rowid not in
(select min(rowid) from 表 group by Id,seq having count()>1)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)