天天看点

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  --用户手动终止