最近,我遇到了一个有关以下内容的采访问题: 更好和更快的方法是更新oracle DB中的表以获取超过100万条记录,为什么? 简单更新:
update employee
set salary = salary + (salary*5%)
where dept_id = l_dept_id
或
使用批量收集和forall语句,如下所示: `
declare
type t_ntt is table of employee.employee_id%TYPE;
l_ntt t_ntt;
l_dept_id INTEGER := 10;
c_limit INTEGER := 10000;
cursor c is select employee_id from employee where dept_id = l_dept_id;
begin
open c;
loop
fetch c into l_ntt limit c_limit;
exit when l_ntt.count = 0;
forall I in indices of l_ntt
update employee
set salary = salary + (salary*5%)
where employee_id = l_ntt(I);
end loop;
close c;
commit;
end;
`