Oracle 行級鎖與表級鎖

來源:互聯網
上載者:User

一、行級鎖:
(下面這句將給該表的所有行都加上鎖)
select * from person for update;

如果該行記錄已經被鎖定,就不用等待,系統會直接拋錯 ora-00054
select * from person  where id = '1'  for update nowait

如果該行記錄已經被鎖定,更新的時候等待5秒,如果這5秒內,該行記錄被解鎖,那麼返回查詢結果,如果5秒內仍未解鎖,那麼系統會直接拋錯 ora-00054
select * from person for update wait 5;

另外,如果使用 select * from person  where id = '1'  for update ,當該行記錄已經被鎖定時,那麼系統將一直等待該行記錄被釋放後,再加鎖。

二、表級鎖:

行共用:允許使用者進行任何操作,禁止獨佔鎖定
lock table person in row share mode;

行排他:允許使用者進行任何操作,禁止共用鎖定
lock table person in row exclusive mode;

共用鎖定:其他使用者只能看,不能修改
lock table person in share mode;

共用行排他:比共用鎖定有更多限制
lock table person in share row exclusive mode;

獨佔鎖定:其他使用者只能看,不能修改,不能加其他鎖
lock table person in exclusive mode;

對於通過lock table命令主動添加的鎖定來說,如果要釋放它們,只需要發出rollback命令即可。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.