【发布时间】:2021-11-25 02:32:21
【问题描述】:
我是 PL/SQL 的新手。 我有一个类似的程序:
create or replace procedure insert_charge is
v_count number;
begin
for i in (select t.name, t.hire_date, t.salary
from emp t
where t.create_date >= (sysdate - 30)
and t.salary = 0) loop
insert into charge
(name, hire_date, salary)
values
(i.name, hire_date, salary);
commit;
update emp l
set l.status = 1
where l.name = i.name
and l.status = 0
and l.hire_date = i.hire_date;
commit;
end loop;
exception
when others then
rollback;
end insert_charge;
如何使用 FORALL 语句代替这个?
【问题讨论】:
-
很高兴您开始进行批量处理,您应该会看到性能有一些显着改善。查看 Oracle 的本教程,看看它是否回答了您的问题:(Oracle Paper)
-
您可以将
bulk collect的所有数据放入一个集合中,然后对insert` 和update应用两个forall语句。使用一些示例数据来演示一个工作示例会更容易。