我正在使用PL/SQL(Oracle 11g)更新EMPLOYEES
表薪金列。使用FOR UPDATE語句
我用兩個獨立的腳本來做同樣的事情,即更新員工的工資。
一個腳本使用FOR UPDATE OF
語句,因爲另一個腳本不使用它。在這兩種情況下,我發現oracle持有行級鎖,直到我們執行命令ROLLBACK
或COMMIT
命令。
那麼兩個腳本之間有什麼區別?
哪一個更好用?
這裏有兩個劇本我談論:
-- Script 1: Uses FOR UPDATE OF
declare
cursor cur_emp
is
select employee_id,department_id from employees where department_id = 90 for update of salary;
begin
for rec in cur_emp
loop
update Employees
set salary = salary*10
where current of cur_emp;
end loop;
end;
--Script 2: Does the same thing like script 1 but FOR UPDATE OF is not used here
declare
cursor cur_emp
is
select employee_id,department_id from employees where department_id = 90;
begin
for rec in cur_emp
loop
update Employees
set salary = salary*10
where Employee_ID = rec.employee_id;
end loop;
end;
我發現,甲骨文收購了在兩種情況下,行級鎖。那麼,使用FOR UPDATE OF
有哪些好處,以及哪種編碼更好?
不要忘記:如果員工== mrp然後設置工資+ = 100000 – stark 2012-08-10 03:17:30