在oracle查詢記錄時給記錄加鎖

實現方法:

利用SELECT的FOR UPDATE子句實現

conn system/manager

--創建實驗用戶
grant connect,resource to test identified by test;

conn test/test

--創建實驗表1
create table a(a number);
insert into a values(1);
commit;

select * from a for update;

select * from a for update of a.a;(a表的a列)

--新打開一個SQL*Plus窗口
conn test/test(test用戶上的第二個會話)
delete from a;

此時,系統停頓狀態,等待解鎖,
只要在第一個窗口發出roll;或commit;命令,即可解除鎖定狀態。 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章