Oracleテーブルの更新
923 ワード
250 wデータ15秒
1つのsqlクエリ文で更新するレコードのrowidとデータ値を検出し、ループバッチでupdateを行うのが原理です.
1つのsqlクエリ文で更新するレコードのrowidとデータ値を検出し、ループバッチでupdateを行うのが原理です.
declare
-- 。 commit。
commit_page_size number default 5000;
cursor cur is
-- select 、 fetch
select t1.name, t.rowid from t_material_instance_his t right join t_material t1 on t.material_code = t1.code
where t.material_name <> t1.name;
-- rowid ' '。oracle ,
col_rowid dbms_sql.Urowid_Table;
-- ' '。oracle ,
col_1 dbms_sql.Varchar2_Table;
begin
open cur;
loop
exit when cur%notfound;
-- into
fetch cur bulk collect into col_1, col_rowid limit commit_page_size;
forall i in 1 .. col_rowid.count
-- update
update t_material_instance_his set material_name = col_1(i) where rowid = col_rowid(i);
commit;
end loop;
end;