Oracle 11g数据库5亿多条数据,没有关键字。不是计算机专业人士做的。需要去重。
首先,创建不重复的关键字的表。
create table temp1 as
select a.a1,a.a2,MAX(a.ROWID) dataid from test a GROUP BY a.a,a.a2
可以多个字段。
然后,去除重复的数据。
使用delete from test where rowid not in (select dataid from temp1)
执行时间太长,60多个小时还没有执行完。
优化,补全temp1的信息创建temp2
create table temp2 as select * from test where rowid in (select dataid from temp1)
执行时间,100多分钟。可以忍受。
重命名原表为test_backup,将temp2重命名为test。创建关键字。
在创建temp2的过程中,需要临时表空间很大,增加临时表空间尺寸后成功。再没有遇到任何问题。
ALTER TABLE temp2 rename to temp22 改名
alter table TEMP22 add constraint pk_temp22 primary key (a1, a2); 加关键字