oracle单表数据移动到最后

2021-06-07 22:37:00
1147533288
原创
1460

大晚上不能白加班,记录一个知识点。


场景:

鼓楼数据造假,首页有些居民信息缺失建档时间和建档机构,每页10条,都有几个缺失项。

领导因嫌弃数据难看,期望把缺失建档时间的数据放到最后。


分析:

考虑删除所有缺失建档时间的数据,重新写入表,实现数据挪到最后。


第一次尝试:

create table personinfo_0607 as select * from personinfo;--备份
create table personinfo_a as select * from personinfo a  where a.input_date is null;--备份缺失建档时间的数据
delete from personinfo where input_date is null;--删除缺失建档时间的数据
commit;
insert  into personinfo select * from personinfo_a a  where a.input_date is null;--重新追加写入
commit;

愿望很美好,现实很残酷,分分钟打脸,顺序无效,跟之前一模一样。


第二次尝试(黑色部分):

create table personinfo_0607 as select * from personinfo;--备份
create table personinfo_a as select * from personinfo a  where a.input_date is null;--备份缺失建档时间的数据
delete from personinfo where input_date is null;--删除缺失建档时间的数据
commit;
insert /*+ APPEND */ into personinfo select * from personinfo_a a  where a.input_date is null;--重新追加写入
commit;


页面验证,问题解决。


注意事项:

确定数据库的归档模式
SELECT NAME,LOG_MODE FROM V$DATABASE;
归档模式: ARCHIVELOG
非归档模式: NOARCHIVELOG


归档模式下,将表设置为 NOLOGGING
ALTER TABLE TABLENAME NOLOGGING;
写入数据
INSERT /*+ APPEND */ INTO TABLENAME1 SELECT * FROM TABLENAME2;

文章分类
联系我
联系人: meepo
电话: *****
Email: 1147533288@qq.com
QQ: 1147533288