在 Oracle 中,您可以基于可以从无限数量的表中获取的游标执行批量更新。这是最快的更新方式。
declare
cursor cur_cur
IS
select t1.rowid row_id, t2.column1, t2.column2
FROM table1 t1
JOIN table2 t2 ON t1.table1_id = t2.table1_id
WHERE whatever
order by row_id
;
type type_rowid_array is table of rowid index by binary_integer;
type type_column1_array is table of table1.column1%type;
type type_column2_array is table of table1.column2%type;
arr_rowid type_rowid_array;
arr_column1 type_column1_array;
arr_column2 type_column2_array;
v_commit_size number := 10000;
begin
open cur_cur;
loop
fetch cur_cur bulk collect into arr_rowid, arr_column1, arr_column2 limit v_commit_size;
forall i in arr_rowid.first .. arr_rowid.last
update table1 tab
SET tab.column1 = arr_column1(i)
, tab.column2 = arr_column2(i)
where tab.rowid = arr_rowid(i)
;
commit;
exit when cur_cur%notfound;
end loop;
close cur_cur;
commit;
exception
when others
then rollback;
raise_application_error(-20000, 'Fout bij uitvoeren update van table1(column1,column2) - '||sqlerrm);
end;