在 Oracle 数据库 11g 中,可以使用另一个临时表空间来存放全局临时表。让我们看一看这种方案的实现方式。
首先,再创建一个临时表空间:
SQL> create temporary tablespace test_temp tempfile ’D:ORACLE11GORADATATESTTEST_TEMP.DBF’ size 20m;
Tablespace created
SQL> create global temporary table my_temp (
2 id number
3 name varchar2 (100))
4 on commit preserve rows
5 tablespace test_temp;
Table created
SQL> select temporary_tablespace from dba_users where username=’HR’;
TEMPORARY_TABLESPACE
------------------------------
TEMP
SQL> select table_name,tablespace_name,logging from user_tables where table_name=’MY_TEMP’;
TABLE_NAME TABLESPACE_NAME LOGGING
------------------------------ ------------------------------ -------
MY_TEMP TEST_TEMP NO
现在,将在表空间 TEST_TEMP 而不是用户的默认临时表空间 (TEMP) 上创建此临时表。
同时,在11g中,可以直接shrink 临时表空间
alter tablespace test_temp shrink space;
alter tablespace test_temp shrink space keep 10m;
比如:
SQL> select bytes,name from v$tempfile where ts#=8 and file#=2;
BYTES NAME
---------- ------------------------------------------------
D:ORACLE11GORADATATESTTEST_TEMP.DBF
SQL> alter tablespace toms_temp shrink space keep 10m;
Tablespace altered
SQL> select bytes,name from v$tempfile where ts#=8 and file#=2;
BYTES NAME
---------- --------------------------------------------------
D:ORACLE11GORADATATESTTEST_TEMP.DBF
SQL>