SQL> COL FILE_NAME format a70SQL> SET linesize 120SQL> SET pagesize 99SQL> COL TABLESPACE_NAME format a10SQL>SQL> SELECT file_name, tablespace_name FROM dba_data_files;FILE_NAME TABLESPACE---------------------------------------------------------------------- ----------/u01/app/oracle/product/10.1.0/db_1/oradata/TEST/users01.dbf USERS/u01/app/oracle/product/10.1.0/db_1/oradata/TEST/sysaux01.dbf SYSAUX/u01/app/oracle/product/10.1.0/db_1/oradata/TEST/undotbs01.dbf UNDOTBS1/u01/app/oracle/product/10.1.0/db_1/oradata/TEST/system01.dbf SYSTEM/u01/app/oracle/product/10.1.0/db_1/oradata/TEST/example01.dbf EXAMPLE/u01/app/oracle/product/10.1.0/db_1/oradata/TEST/foo1.dbf FOO6 rows selected.
該命令的文法很簡單:
ALTER TABLESPACE tablespacename RENAME TO newtablespacename;
SQL>ALTER TABLESPACE foo RENAME TO test;Tablespace altered.SQL> SELECT file_name, tablespace_name FROM dba_data_files;FILE_NAME TABLESPACE---------------------------------------------------------------------- ----------/u01/app/oracle/product/10.1.0/db_1/oradata/TEST/users01.dbf USERS/u01/app/oracle/product/10.1.0/db_1/oradata/TEST/sysaux01.dbf SYSAUX/u01/app/oracle/product/10.1.0/db_1/oradata/TEST/undotbs01.dbf UNDOTBS1/u01/app/oracle/product/10.1.0/db_1/oradata/TEST/system01.dbf SYSTEM/u01/app/oracle/product/10.1.0/db_1/oradata/TEST/example01.dbf EXAMPLE/u01/app/oracle/product/10.1.0/db_1/oradata/TEST/foo1.dbf TEST
因為 system 和 sysaux 這兩個資料表空間的特殊性,是不可以更名的:
SQL> ALTER TABLESPACE system RENAME TO mysystem;ALTER TABLESPACE system RENAME TO mysystem*ERROR at line 1:ORA-00712: cannot rename system tablespaceSQL> ALTER TABLESPACE sysaux RENAME TO mysysaux;ALTER TABLESPACE sysaux RENAME TO mysysaux*ERROR at line 1:ORA-13502: Cannot rename SYSAUX tablespace
SQL> ALTER tablespace undotbs1 RENAME TO undotbs; Tablespace altered.SQL> SQL> show parameter pfile NAME TYPE VALUE------------------------------------ ----------- ------------------------------spfile string /u01/app/oracle/product/10.1.0 /db_1/dbs/spfileTEST.oraSQL> show parameters undoNAME TYPE VALUE------------------------------------ ----------- ------------------------------undo_management string AUTOundo_retention integer 900undo_tablespace string UNDOTBS1SQL> shutdown immediate;Database closed.Database dismounted.ORACLE instance shut down.SQL> startupORACLE instance started.Total System Global Area 180355072 bytesFixed Size 777996 bytesVariable Size 128983284 bytesDatabase Buffers 50331648 bytesRedo Buffers 262144 bytesDatabase mounted.Database opened.SQL> show parameters undoNAME TYPE VALUE------------------------------------ ----------- ------------------------------undo_management string AUTOundo_retention integer 900undo_tablespace string UNDOTBSSQL>
對離線資料表空間的更名是不允許的:
SQL> ALTER TABLESPACE TEST OFFLINE;Tablespace altered.SQL> ALTER TABLESPACE test RENAME TO testoffline; ALTER TABLESPACE test RENAME TO testoffline*ERROR at line 1:ORA-01135: file 6 accessed for DML/query is offlineORA-01110: data file 6:'/u01/app/oracle/product/10.1.0/db_1/oradata/TEST/foo1.dbf'
SQL> ALTER TABLESPACE TEST ONLINE;Tablespace altered.SQL> ALTER TABLESPACE TEST READ ONLY;Tablespace altered.SQL> ALTER TABLESPACE test RENAME TO testreadonly;Tablespace altered.SQL> list 1* SELECT file_name, tablespace_name FROM dba_data_filesSQL> /FILE_NAME TABLESPACE---------------------------------------------------------------------- ----------/u01/app/oracle/product/10.1.0/db_1/oradata/TEST/users01.dbf USERS/u01/app/oracle/product/10.1.0/db_1/oradata/TEST/sysaux01.dbf SYSAUX/u01/app/oracle/product/10.1.0/db_1/oradata/TEST/undotbs01.dbf UNDOTBS/u01/app/oracle/product/10.1.0/db_1/oradata/TEST/system01.dbf SYSTEM/u01/app/oracle/product/10.1.0/db_1/oradata/TEST/example01.dbf EXAMPLE/u01/app/oracle/product/10.1.0/db_1/oradata/TEST/foo1.dbf TESTREADONLY6 rows selected.SQL>
看來資料字典已經更新,不過Oracle會向alert_SID.log 中寫入類似如下的日誌:
ALTER TABLESPACE test RENAME TO testreadonly Sat Nov 13 16:15:21 2004 Tablespace 'TEST' is renamed to 'TESTREADONLY'. Tablespace name change is not propagated to file headersbecause the tablespace is read only. Completed: ALTER TABLESPACE test RENAME TO testreadonly