What makes difference, when I use FOR UPDATE OF SAL
or simply write FOR UPDATE
.
According to O'Reilly
The OF list of the FOR UPDATE clause does not restrict you to changing only those columns listed. Locks are still placed on all rows; the OF list just gives you a way to document more clearly what you intend to change. If you simply state FOR UPDATE in the query and do not include one or more columns after the OF keyword, then the database will then lock all identified rows across all tables listed in the FROM clause.
Which means, when I specify column name with FOR UPDATE OF SAL
, other user can make change with SAL
column only. But, practically, this is not the case. I'm still getting lock in other session. Can anyone explain the difference.
UPDATE
----- SESSION 1
declare
emp_info emp.ename%type;
cursor emp_cur is select ename from emp join dept using(deptno) where deptno=&no for update of sal;
begin
open emp_cur;
loop
fetch emp_cur into emp_info;
exit when emp_cur%notfound;
dbms_output.put_line(emp_info);
end loop;
close emp_cur;
end;
----- SESSION 2
update emp set comm=5 where deptno=10;
---- hanged/waiting in session 2