在對指定表做append操作,其他再做truncate時候,會產(chǎn)生鎖表,如下驗證步驟,
在察哈爾右翼前等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都做網(wǎng)站、網(wǎng)站制作、成都外貿(mào)網(wǎng)站建設(shè) 網(wǎng)站設(shè)計制作按需策劃設(shè)計,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),營銷型網(wǎng)站,成都外貿(mào)網(wǎng)站建設(shè),察哈爾右翼前網(wǎng)站建設(shè)費用合理。
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
這個和鎖定機制沒什么關(guān)系吧?你的需求只需要邏輯標(biāo)識就可以滿足了。
可以設(shè)定一個 鎖定狀態(tài)的字段,例如 LOCK 等等,名字你自己根據(jù)業(yè)務(wù)場景自己取了。當(dāng)提交領(lǐng)導(dǎo)審批這步之后,LOCK字段設(shè)置一個值,例如1,為鎖定狀態(tài),其他業(yè)務(wù)操作時先取得此字段狀態(tài)是否為1,為1不可修改。
領(lǐng)導(dǎo)批準(zhǔn)了之后,記錄不可修改,LOCK=1不動,如拒絕,LOCK=0,可重新修改。
這樣就可以滿足你的需求了,采用鎖機制并不能滿足你的要求。因為你不知道領(lǐng)導(dǎo)什么時候去審批通過,你總不能這一段時間之內(nèi)都占用ORACLE的鎖吧?這是不合理的。
希望能對你有幫助。
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.