--测试select... for update为行锁 declare CURSOR cur_dept IS SELECT * FROM dept WHERE deptno = 10 FOR UPDATE; begin FOR r IN cur_dept LOOP IF r.dname = 'ACCOUNTING' THEN dbms_lock.sleep(120); UPDATE dept SET dname = dname || 'ACCOUNTING_NEW' WHERE CURRENT OF cur_dept; ELSE UPDATE dept SET dname = 'BAD' WHERE CURRENT OF cur_dept; END IF; END LOOP; COMMIT; end;
--在该代码执行的过程中,更新deptno = 10,会被阻塞,而更新deptno = 20不受阻塞 |
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/17013648/viewspace-1150216/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/17013648/viewspace-1150216/