遷移使用者物件從一個表空間到另外表空間

shilei1發表於2010-12-01
例如:

select 'alter table smngdb. '||table_name||' move tablespace XMYJ' from dba_tables where wner='SMNGDB'

 

select 'alter table '||tname||' move  tablespace user1' from tab where rownum<=3;


結果示例:

'ALTERTABLESYS.'||TABLE_NAME||'MOVETABLESPACEEXAMPLE'
----------------------------------------------------------------------
alter table sys.MGMT_JOB_CRED_PARAMS move tablespace EXAMPLE
alter table sys.MGMT_JOB_SUBST_PARAMS move tablespace EXAMPLE
alter table sys.MGMT_JOB_PROP_PARAMS move tablespace EXAMPLE
alter table sys.MGMT_JOB_VALUE_PARAMS move tablespace EXAMPLE
alter table sys.MGMT_JOB_SEC_INFO move tablespace EXAMPLE
alter table sys.MGMT_JOB_LOCK_INFO move tablespace EXAMPLE
alter table sys.MGMT_JOB_LOCK_TARGETS move tablespace EXAMPLE
alter table sys.MGMT_JOB_SCHEDULE move tablespace EXAMPLE
alter table sys.MGMT_JOB move tablespace EXAMPLE
alter table sys.MGMT_JOB_TARGET move tablespace EXAMPLE
alter table sys.MGMT_JOB_FLAT_TARGETS move tablespace EXAMPLE

'ALTERTABLESYS.'||TABLE_NAME||'MOVETABLESPACEEXAMPLE'

 

要求from後面的資料字典中要有||連線符中間的欄位。

 

PL/SQL中的一些符號:
:= 賦值運算子號
|| 連線運算子號
-- 單行註釋符號
/* ... */ 多行註釋符號
<> 標籤分隔符號
.. 範圍運算子號
** 求冪運算子號

 

-----------------

首先移動表:
alter table table_name move tablespace tablespace_name;
然後,如果有索引的話必須重建索引:
alter index index_name rebuild tablespace tablespace_name

可以使用spool來幫助實現多個表的操作:
set header off;
spool /export/home/oracle/alter_tables.sql;
select 'alter table '||object_name||' move tablespace 表空間名'
from dba_objects
where wner='xxxx' and object_type='TBALE';
spool off;
之後執行此sql腳步即可
同樣對於index也做同樣的操作。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/196700/viewspace-680737/,如需轉載,請註明出處,否則將追究法律責任。

相關文章