for update 和 for update of 有什麼區別

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

鎖定兩個表的所有記錄
這個有語句是鎖定倆表的符合id匹配條件的所有記錄,而不是鎖定倆表的所有記錄.予以更正
 
這個有語句是鎖定倆表的符合id匹配條件的所有記錄,而不是鎖定倆表的所有記錄.予以更正
 
這個有語句是鎖定倆表的符合id匹配條件的所有記錄,而不是鎖定倆表的所有記錄.予以更正
 
(這個有語句是鎖定倆表的符合id匹配條件的所有記錄,而不是鎖定倆表的所有記錄.予以更正)

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 of 說得不對,根據oracle文檔,它是用來鎖字段的。

http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10826/pco03dbc.htm#i4233

Restrictions

You cannot use FOR UPDATE with multiple tables, but you must use FOR UPDATE OF toidentify a column in the table that you want locked.Row locks obtained by a FOR UPDATE statement are cleared by a COMMIT, which explains why the cursor is closed for you. If you try to fetch from a FOR UPDATE cursor after a commit, Oracle generates a Fetch out of Sequence error.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章