天天看點

oracle鎖表語句執行提示無法終止目前對話_ORACLE LOCK TABLE 無法鎖定表?

第三步報錯ORA-00054和LOCK table無關,

而是和和第二步insert沒有送出有關。

insert已經其他DML語句執行的時候會給相關對象加個TM鎖,以防止該對象再被操作的時候(DML--資料操控語言)發生結構改變,即使DDL語句。

SQL> create table t1 (c1 char(2));

Table created.

SQL> select userenv('SID') from dual;

USERENV('SID')

--------------

1596

SQL> insert into t1 values('1');

1 row created.

SQL> select type,id1,id2 from v$lock where sid='1596';

TY          ID1             ID2

-- ---------- ----------

AE          100               0

TM     593805               0

TX    3670041        37004435

3 rows selected.

SQL> select object_name from dba_objects where object_id=593805;

OBJECT_NAME

------------------------------

T1

1 row selected.

這時候在另外一個會話裡

SQL> truncate table t1;

truncate table t1

*

ERROR at line 1:

ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired

SQL> lock table t1 in exclusive mode nowait;

lock table t1 in exclusive mode nowait

*

ERROR at line 1:

ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired

SQL> lock table t1 in exclusive mode;  --一直等待,

lock table t1 in exclusive mode

*

ERROR at line 1:

ORA-01013: user requested cancel of current operation --使用者手動終止

SQL> alter table t1 add (c2 number); --一直等待

alter table t1 add (c2 number)

*

ERROR at line 1:

ORA-01013: user requested cancel of current operation  --使用者手動終止