有一個大表,大表因爲錄入時候有個空置,如今將空置賦予日期

1.該表很大,8t,由三列,其中create_time,如今要求修改爲非空值,因爲數據量比較大,所以採用分批來增長。 ide

腳本以下
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'); oop

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_timeget

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

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

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

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

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

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

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;

相關文章
相關標籤/搜索