天天看點

Oracle的表空間遷移

Oracle的表空間遷移

移植表空間

alter table TABLE_NAME move tablespace TABLESPACENAME      

将資料從一個表空間移植到另一個表空間

select 'alter table ' ||table_name || ' move tablespace systemportal;' from user_all_tables where tablespace_name='OA';      

當導完資料後需要重建立立索引 否則報錯

1. select index_name from user_indexes where status = 'UNUSABLE' 查詢失效索引
2. alter index 索引名 rebuild;  重建立立索引      

如果失效索引太多 那麼可以執行以下過程

1. 
2. declare
3.   vc_index_name varchar2(100); --索引名稱
4. cursor index_cur is
5. select index_name from user_indexes where status = 'UNUSABLE'; --擷取目前登入使用者所有不可用的索引
6. begin
7. open index_cur;
8. fetch index_cur into vc_index_name;
9.   loop
10.     exit when not index_cur%found;
11. --dbms_output.put_line(vc_index_name);
12. execute immediate 'alter index '||vc_index_name||' rebuild';
13. fetch index_cur into vc_index_name;
14. end loop;
15. close index_cur;
16. end;