собственно ответ на вопросы:
How to move LOB data to another tablespace?
How to move user tables to a different tablespace?
How to move user indexes to a different tablespace?
скрипт пока не умеет перемещать индекс-таблицы и секционированные таблицы.
- DECLARE
- table_ts_name VARCHAR2 (30) := 'USER_DATA';
- index_ts_name VARCHAR2 (30) := 'USER_INDEX';
- varUser VARCHAR2(30) := 'HR';
- BEGIN
- FOR obj
- IN ( -- перемещение таблиц содержащих поля LOB типов
- SELECT 'alter table '||owner||'.'|| table_name||' move lob('|| column_name
- ||') store as (tablespace '|| table_ts_name move_sql
- FROM dba_tab_cols
- WHERE owner=varUser and data_type='%LOB'
- UNION ALL
- -- перемещение остальных таблиц
- SELECT 'alter table '||t1.owner|| '.'||t1.object_name||' move tablespace '||table_ts_name move_sql
- FROM all_objects t1
- WHERE t1.owner=varUser
- AND t1.object_type = 'TABLE'
- AND t1.temporary = 'N'
- AND EXISTS (
- SELECT 1 from dba_tab_cols t2
- where t1.owner = t2.owner
- AND t1.object_name = t2.table_name
- AND t2.data_type <> 'LONG'
- AND t2.data_type <> 'LONG RAW')
- UNION ALL
- -- перемещение и ребилд индексов, за исключением IOT индексов
- SELECT 'alter index '||owner||'.'|| index_name|| ' rebuild tablespace '|| index_ts_name move_sql
- FROM all_indexes
- WHERE owner=varUser AND index_type <> 'IOT - TOP')
- LOOP
- dbms_output.put_line(obj.move_sql);
- EXECUTE IMMEDIATE obj.move_sql;
- END LOOP;
- END;
* This source code was highlighted with
Source Code Highlighter.