select for update

select * from TTable1 for update  锁定表的所有行,只能读不能写

select * from TTable1 where pkid = 1 for update  只锁定pkid=1的行

select  * from Table1 a join Table2 b on a.pkid=b.pkid for update   锁定俩表的符合id匹配条件的所有记录

select  * from Table1 a join Table2 b on a.pkid=b.pkid  where  a.pkid = 10 for update  锁定两个表的中满足条件的行

select  * from Table1 a join Table2 b on a.pkid=b.pkid  where  a.pkid = 10 for update of a.pkid  只锁定Table1中满足条件的行
 
for update of ,根据 oracle文档,它是用来锁字段的。
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10826/pco03dbc.htm#i4233

-------------------------------------测试例子--------------------------------------------------------------
BEGIN;
SELECT * FROM test where id =2 FOR UPDATE;
----在提交之前如果(UPDATE test set xx = xx WHERE id =2),则会一直等待。知道commit (解锁)之后再执行。其他id 如3 等 则不受影响
COMMIT;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值