如何删除在 会话1 下创建的临时表
1.错误示例:
1.直接在会话1删除
ERROR at line 1:
ORA-14452: attempt to create, alter or drop an index on temporary table already in use
报错原因:该临时表正在当前会话使用,不能删除正在当前会话使用的临时表
2.在 会话2 删除
依然会报错:
ERROR at line 1:
ORA-14452: attempt to create, alter or drop an index on temporary table already in use
报错原因:在会话1创建的临时表,会话一此时还没有断开,所以该表无法删除。
2.解决方法
将 会话1 结束,然后在 会话2 中删除临时表
过程中会用到两个命令:
1.查看会话id
SELECT s.sid, s.serial#, s.username, s.program, s.osuser, s.machine, s.logon_time
FROM v$session s
JOIN v$sql sql ON s.sql_id = sql.sql_id
WHERE sql.sql_text LIKE '%temp_table%';
2.删除会话
注意:无法删除当前会话,只能从另一个会话中删除
如果删除当前会话会报错:
ERROR at line 1:
ORA-00027: cannot kill current session
解决方法:
查询要删除的会话id,在另一个会话中删除该会话。
3.删除方法:
ALTER SYSTEM KILL SESSION 'session_id,serial#' IMMEDIATE;
其中,session_id
和 serial#
是你要终止的会话的标识符。
当 会话1 断开后,就可以在 会话2 删除临时表了
drop table temp_table
识符。
当 会话1 断开后,就可以在 会话2 删除临时表了
```sql
drop table temp_table