oracle-for update 与 for update of

来源:互联网 发布:dnf双开网络中断 编辑:程序博客网 时间:2024/05/29 02:22

本文转载自:http://blog.csdn.net/indieinside/article/details/13296695

1 select * from TTable1 for update 锁定表的所有行,只能读不能写
  2  select * from TTable1 where pkid = 1 for update 只锁定pkid=1的行
  3  select * from Table1 a join Table2 b on a.pkid=b.pkid for update 锁定两个表的所有记录
  4 select * from Table1 a join Table2 b on a.pkid=b.pkid where a.pkid = 10 for update 锁定两个表的中满足条件的行
  5. select * from Table1 a join Table2 b on a.pkid=b.pkid where a.pkid = 10 for update of a.pkid 只锁定Table1中满足条件的行
  for update 是把所有的表都锁点 for update of 根据of 后表的条件锁定相对应的表

select * from emp where empno = 7369 for update; 会对表中员工编号为7369的记录进行上锁。其他用户无法对该记录进行操作,只能查询。select * from emp where empno = 7369 for update of sal; 这条语句是不是意味着只对表中的7369 这一行的sal字段的数据进行了上锁,其他数据则可以被其他用户做更新操作呢。学员测试结果为二条语句的效果是一样的。

在对多个表进行锁定时for update of才会起作用,用户1进行如下操作(of 后面可以使table1中任意字段):

select * from table1 a, table2 b where a.filed1 = b.filed1
for update of a.filed1 ;

用户2进行如下操作时可以对table2进行锁定,因为用户1只对table1进行了锁定:

select * from table2 b
for update


阅读全文
0 0
原创粉丝点击