select for update

来源:互联网 发布:在淘宝上开店货源怎么办 编辑:程序博客网 时间:2024/06/05 10:38
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;