--首先模拟环境 SQL> CREATE GLOBAL TEMPORARY TABLE t_tmp_t1 2 (a NUMBER(2));
Table created
SQL> SQL> INSERT INTO t_tmp_t1 2 VALUES(1);
1 row inserted
SQL> --新开session测试 SQL> ALTER TABLE t_tmp_t1 ADD c NUMBER(2) ;
ALTER TABLE t_tmp_t1 ADD c NUMBER(2)
ORA-14450: attempt to access a transactional temp table already in USE --查找sid及serial# SQL> SELECT DISTINCT a.sid,a.SERIAL# FROM v$session a,v$sql b,v$enqueue_lock c 2 WHERE a.SID=c.SID AND c.TYPE='TO' AND a.MODULE_HASH=b.MODULE_HASH AND lower(b.SQL_TEXT) LIKE '%t_tmp_t1%';
SID SERIAL# ---------- ---------- 129 144
--使用sys用户登陆 SQL> alter system kill session '129,144';
System altered
SQL> --回到scott SQL> ALTER TABLE t_tmp_t1 ADD c NUMBER(2) ;
Table altered
SQL> desc t_tmp_t1 Name Type Nullable Default Comments ---- --------- -------- ------- -------- A NUMBER(2) Y C NUMBER(2) Y
找到TO的定义了.感觉上面的应该能解决啊,你查找sid的时候查找的表名改没? SQL> SELECT * FROM v$lock_type t WHERE t.TYPE='TO';
TYPE NAME ID1_TAG ID2_TAG IS_USER DESCRIPTION ---------------------------------------------------------------- ---------------------------------------------------------------- ---------------------------------------------------------------- ---------------------------------------------------------------- ------- -------------------------------------------------------------------------------- TO Temp Object object # 1 NO Synchronizes DDL and DML operations on a temp object
V$LOCK_TYPE is a good starting point!SQL> select type,name,description from v$lock_type where type in ('AE', 'TO');TYPE NAME DESCRIPTION ---- -------------------- ------------------------------------------------------------ AE Edition Lock Prevent Dropping an edition in use TO Temp Object Synchronizes DDL and DML operations on a temp objectAE is about application code versioning (editions) which should be released as part of Oracle 11.2 I think. TO is about temp tables so someone wouldn't be able to drop or alter the structure of the table def while there's some other session having data in the temp tab.-- Tanel Poder http://blog.tanelpoder.com
把对应的session kill掉试试.
本机试验是成功的.
俺就是想知道有哪些session正在使用这个临时表。。
不知道session id,怎么杀啊?
本机当然没问题。
SQL> CREATE GLOBAL TEMPORARY TABLE t_tmp_t1
2 (a NUMBER(2));
Table created
SQL>
SQL> INSERT INTO t_tmp_t1
2 VALUES(1);
1 row inserted
SQL>
--新开session测试
SQL> ALTER TABLE t_tmp_t1 ADD c NUMBER(2) ;
ALTER TABLE t_tmp_t1 ADD c NUMBER(2)
ORA-14450: attempt to access a transactional temp table already in USE
--查找sid及serial#
SQL> SELECT DISTINCT a.sid,a.SERIAL# FROM v$session a,v$sql b,v$enqueue_lock c
2 WHERE a.SID=c.SID AND c.TYPE='TO' AND a.MODULE_HASH=b.MODULE_HASH AND lower(b.SQL_TEXT) LIKE '%t_tmp_t1%';
SID SERIAL#
---------- ----------
129 144
--使用sys用户登陆
SQL> alter system kill session '129,144';
System altered
SQL>
--回到scott
SQL> ALTER TABLE t_tmp_t1 ADD c NUMBER(2) ;
Table altered
SQL> desc t_tmp_t1
Name Type Nullable Default Comments
---- --------- -------- ------- --------
A NUMBER(2) Y
C NUMBER(2) Y
SQL>
多謝樓上熱心詳細的解答。。查找sid及serial#你用到v$enqueue_lock:這個是enqueue對象所有的鎖
用戶在使用這個臨時表,這個臨時表不會被鎖啊,所以查到的數據是空的。。
SQL> SELECT * FROM v$lock_type t WHERE t.TYPE='TO';
TYPE NAME ID1_TAG ID2_TAG IS_USER DESCRIPTION
---------------------------------------------------------------- ---------------------------------------------------------------- ---------------------------------------------------------------- ---------------------------------------------------------------- ------- --------------------------------------------------------------------------------
TO Temp Object object # 1 NO Synchronizes DDL and DML operations on a temp object
SQL>
http://comp.mailarchive.ca/databases.oracle.server/2003-06/1767.html
'TO');TYPE NAME DESCRIPTION
---- --------------------
------------------------------------------------------------
AE Edition Lock Prevent Dropping an edition in use
TO Temp Object Synchronizes DDL and DML operations on a temp
objectAE is about application code versioning (editions) which should be released
as part of Oracle 11.2 I think.
TO is about temp tables so someone wouldn't be able to drop or alter the
structure of the table def while there's some other session having data in
the temp tab.--
Tanel Poder
http://blog.tanelpoder.com