您提到您正在创建临时表,但大概您已经创建了一次,并且没有尝试在每次 plsql 代码运行时重新创建它,并且索引定义可以保留在临时表上 - 这也不需要创建每次运行代码。
全局临时表具有静态定义 - 您只需创建它,它就在那里,但它不会生成重做/撤消,并且其中包含的数据仅对填充它的会话可见。
SQL*Plus: Release 10.1.0.4.2 - Production on Wed Oct 26 01:22:30 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
SQL> create global temporary table test (name varchar2(20));
Table created.
SQL> insert into test values ('one');
1 row created.
SQL> insert into test values ('two');
1 row created.
SQL> select * from test;
NAME
--------------------
one
two
然后在另一个会话中
SQL*Plus: Release 10.1.0.4.2 - Production on Wed Oct 26 01:23:17 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
SQL> select * from test;
no rows selected
SQL> insert into test values ('three');
1 row created.
SQL> select * from test;
NAME
--------------------
three
回到第一个会话
SQL> 提交;
Commit complete.
SQL> select * from test;
no rows selected
SQL> drop table test;
drop table test
*
ERROR at line 1:
ORA-14452: attempt to create, alter or drop an index on temporary table already
in use
因为我们在第二个会话中插入了数据,所以我们不能对临时表做任何事情
直到我们在第二个会话中提交,然后 drop 成功
您可以选择在提交时(在提交删除行时)或保留数据直到会话终止(在提交保留行时)为创建它的会话清除内容。