ORA-14450: attempt to access a transactional temp table already in use

在ORACLE數據中修改會話級臨時表時,有可能會遇到ORA-14550錯誤,那麼爲何會話級全局臨時表會報ORA-14450錯誤呢,以下所示,咱們先從一個小小案例入手: 數據庫

案例1:session

SQL> CREATE GLOBAL TEMPORARY TABLE TEMP_TEST
  2  (
  3     NAME VARCHAR2(12)
  4  ) ON COMMIT PRESERVE ROWS;
 
Table created.
 
SQL> INSERT INTO TEMP_TEST VALUES('kerry');
 
1 row created.
 
SQL> COMMIT;
 
Commit complete.
 
SQL> ALTER TABLE TEMP_TEST ADD SEX NUMBER(1) ;
ALTER TABLE TEMP_TEST ADD SEX NUMBER(1)
*
ERROR at line 1:
ORA-14450: attempt to access a transactional temp table already in use

如上所示,修改會話級臨時表時遇到了ORA-14450錯誤,那麼有哪些解決方法呢? 這時須要斷開會話或執行TRUNCATE語句:oracle

SQL> TRUNCATE TABLE TEMP_TEST;
 
Table truncated.
 
SQL>  ALTER TABLE TEMP_TEST ADD SEX NUMBER(1) ;
 
Table altered.
 
SQL>

以下所示,咱們模擬一個會話在操做臨時表TEMP_TEST, 另一個會話準備修改它,以下所示(實際場景可能更復雜,可能涉及多個會話而不是僅僅兩個會話) app

會話1:spa

SQL> SET SQLPROMPT "SQLSESSION 1 >"
SQLSESSION 1 >CREATE GLOBAL TEMPORARY TABLE TEMP_TEST
  2           (
  3              NAME VARCHAR2(12)
  4           ) ON COMMIT PRESERVE ROWS;
 
Table created.
 
SQLSESSION 1 >INSERT INTO TEMP_TEST VALUES('kerry');
 
1 row created.
 
SQLSESSION 1 >COMMIT;
 
Commit complete.
 
SQLSESSION 1 >

會話2::code

SQL> SET SQLPROMPT "SESSION 2 >"
SESSION 2 >ALTER TABLE TEMP_TEST ADD SEX NUMBER(1) ;
ALTER TABLE TEMP_TEST ADD SEX NUMBER(1)
*
ERROR at line 1:
ORA-14450: attempt to access a transactional temp table already in use
 
 
SESSION 2 >

那麼此時,會話1是其它用戶登陸的。好比應用程序等,你不可能要求全部會話都去執行TRUNCATE操做,這個時候該怎麼處理呢? server

此時你能夠使用下面步驟解決這個問題。 blog

Step 一、以sys或system登陸數據庫,先從DBA_OBJECTS中查詢到該表的OBJECT_ID:進程

SELECT OWNER, OBJECT_ID,OBJECT_TYPE 
  FROM DBA_OBJECTS 
    WHERE OBJECT_NAME=&OBJECT_NAME AND OBJECT_TYPE ='TABLE';

Step 二、根據查到的OBJECT_ID知道使用該表的SESSION:ip

SELECT ADDR, KADDR, SID,LMODE FROM V$LOCK WHERE ID1=&OBJECT_ID;

Step 三、經過下面SQL找到對應的會話並生成KILL SESSION的執行語句

SET COL kill_session FOR A80;
select a.sid, a.serial#,a.status,
       a.paddr, 'alter system kill session ''' 
                    || a.sid || ',' || a.serial# 
                    || ''' immediate;' AS kill_session
FROM v$session a
WHERE a.sid in (select sid from v$enqueue_lock t where t.type='TO') 
  and a.sid=&sid;

Step 四、查看會話狀態,並執行ALTER SYSTEM KILL SESSION語句殺掉這些進程:

具體操做步驟,以下截圖所示: 

clip_image002


緣由: 查看ORA-14450的錯誤,你能夠看到以下信息:

[oracle@oracle-server ~]$ oerr ora 1445014450, 00000, "attempt to access a transactional temp table already in use"// *Cause:  An attempt was made to access a transactional temporary table that//          has been already populated by a concurrent transaction of the same//          session.// *Action: do not attempt to access the temporary table until the//          concurrent transaction has committed or aborted.

相關文章
相關標籤/搜索