温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

有一个大表,大表由于录入时候有个空置,现在将空置赋予日期

发布时间:2020-06-30 10:19:26 来源:网络 阅读:191 作者:李石岩 栏目:关系型数据库

1.该表很大,8t,由三列,其中create_time,现在要求修改成非空值,由于数据量比较大,因此采用分批来增加。

脚本如下
create or replace procedure PRC_UPDATE_CREATE_TIME is
start_num integer;
start_date date;
total number;
update_count integer;
per_loop_count integer;
begin
dbms_output.put_line('Start to batch update');

start_num := 1; -- start value of cycle
per_loop_count := 100; -- per cycle handle count
start_date := to_date('20100101', 'YYYYMMDD'); -- start date of create_time

/ get total number of the update records /
select count(1) into total from tmp_loan_file_data
where CREATE_TIME is null;

dbms_output.put_line('total number:');
dbms_output.put_line(total);

update_count := total/per_loop_count;
if (mod(total, per_loop_count) > 0) then
update_count := update_count + 1;
end if;

dbms_output.put_line('loop times:');
dbms_output.put_line(update_count);

/ Loop to update records /
while start_num <= update_count loop

dbms_output.put_line('loop seq :');
dbms_output.put_line(start_num);

merge into tmp_loan_file_data src_tab
using (select t.rowid as rid
from tmp_loan_file_data t
where t.CREATE_TIME is null
and rownum >=1
and rownum <= per_loop_count) sel_tmp
on (src_tab.rowid = sel_tmp.rid)
when matched then
update set CREATE_TIME = start_date;

start_num := start_num + 1;
start_date := start_date + 1;
commit;
end loop;

dbms_output.put_line('End batch update');
end PRC_UPDATE_CREATE_TIME;

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI