移動表空間的指令碼

chance2000發表於2010-07-19

Remark Set SQL*Plus variables to manipulate output
set feedback off heading off verify off trimspool off
set pagesize 0 linesize 200
set sqlterminator '/'
Remark Set SQL*Plus user variables used in this script
define movetablespace = 'movetbs.sql'
define usrlist = '''SCOTT'',''ESYS'''
prompt *** Spooling to &movetablespace.
Remark 建立移動表空間的指令碼
spool &movetablespace
SELECT 'ALTER TABLE ' || A.OWNER || '.' || A.TABLE_NAME ||
' MOVE TABLESPACE ' || B.DEFAULT_TABLESPACE || ';' AS CMD
FROM (SELECT OWNER, TABLE_NAME,TABLESPACE_NAME FROM ALL_TABLES WHERE OWNER IN (&usrlist.)) A,
(SELECT USERNAME, DEFAULT_TABLESPACE
FROM DBA_USERS
WHERE USERNAME IN (&usrlist.)) B
WHERE A.OWNER = B.USERNAME
AND A.TABLESPACE_NAME <> B.DEFAULT_TABLESPACE
/

spool off

set sqlterminator ';'

@&movetablespace.

host del &movetablespace.

exit

重建索引的表空間也類似

[@more@]

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

相關文章