在對指定表做append操作,其他再做truncate時候,會產(chǎn)生鎖表,如下驗(yàn)證步驟,
網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、微信小程序定制開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了山陰免費(fèi)建站歡迎大家使用!
1、創(chuàng)建測試表,
create table test_lock(id number, value varchar2(200));
2、執(zhí)行append語句;并且不做提交,insert /*+append*/ into test_lock values(1,1);
3、再次執(zhí)行清表語句,truncate table test_lock;報鎖表錯誤,
4、查看鎖表語句,發(fā)現(xiàn)被鎖表,
select b.object_name, t.*
from v$locked_object t, user_objects b
where t.object_id = b.object_id
lock table 表名 exclusive mode nowait; -- 鎖整個表
select * from 表名 where XXX for update nowaitl -- 鎖符合條件的記錄
鎖表:LOCK TABLE tablename IN 鎖模式 MODE;
解鎖:commit或rollback;
鎖模式有以下幾種:
ROW SHARE
ROW SHARE permits concurrent access to the locked table but prohibits users from locking the entire table for exclusive access. ROW SHARE is synonymous with SHARE UPDATE, which is included for compatibility with earlier versions of Oracle Database.
ROW EXCLUSIVE
ROW EXCLUSIVE is the same as ROW SHARE, but it also prohibits locking in SHARE mode. ROW EXCLUSIVE locks are automatically obtained when updating, inserting, or deleting.
SHARE UPDATE
See ROW SHARE.
SHARE
SHARE permits concurrent queries but prohibits updates to the locked table.
SHARE ROW EXCLUSIVE
SHARE ROW EXCLUSIVE is used to look at a whole table and to allow others to look at rows in the table but to prohibit others from locking the table in SHARE mode or from updating rows.
EXCLUSIVE
EXCLUSIVE permits queries on the locked table but prohibits any other activity on it.
1、在做Oracle監(jiān)聽程序測試時,發(fā)現(xiàn)帳戶已經(jīng)被鎖定。
2、在數(shù)據(jù)庫安裝電腦上,點(diǎn)擊開始打開運(yùn)行窗口。
3、在運(yùn)行窗口輸入CMD,調(diào)出命令提示符界面。
3、在命令提示符下面,用管理員身份登入到數(shù)據(jù)庫sqlplus / as sysdba。
4、輸入解鎖命令alter user Scott account unlock后回車。
5、看見用戶已更改的字樣,表示命令已成功執(zhí)行。
6、再切換到監(jiān)聽程序驗(yàn)證,原來的ora-28000帳戶被鎖定的提示已經(jīng)不存在了。用戶解鎖成功。