простое обновление (SQL) и массовое обновление (PLSQL) - PullRequest
0 голосов
/ 24 июня 2019

Недавно я наткнулся на вопрос об интервью: что лучше и быстрее было обновить таблицу в oracle DB для более чем 1 миллиона записей и почему? простое обновление:

update employee
set salary = salary + (salary*5%)
where dept_id = l_dept_id

или

с использованием группового сбора и выписки: `

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;

`

...