The following SQL generates SQL to move the existing objects; you will want to change the criteria as needed for your situation; this shows moving objects owned by SCOTT from SYSAUX tablespace to TARGET_TS:
Tables
select 'alter table ' || do.owner || '.' || do.object_name || ' move tablespace TARGET_TS;' as cmd_to_invoke from dba_objects do, dba_segments ds, dba_tables dt where do.owner = 'SCOTT' and do.owner=ds.owner and do.owner=dt.owner and do.object_name = ds.segment_name and do.object_name=dt.table_name and dt.iot_name is null and do.object_type='TABLE' and ds.tablespace_name = 'SYSAUX';
Partitioned Tables
alter table SCOTT.EMP modify default attributes tablespace TARGET_TS;
-- Then invoke the SQL generated by this query:
select distinct 'alter table ' || dt.table_owner || '.' || dt.table_name || ' move partition ' || dt.partition_name || ' tablespace TARGET_TS' || ';' as cmd_to_invoke from dba_tab_partitions dt where dt.table_owner='SCOTT'and dt.tablespace_name='SYSAUX' order by 1;
IOT Tables
select 'alter table ' || owner || '.' || table_name || ' move tablespace DEF_TABLESPACE;' from dba_indexes where owner = 'SCOTT' and index_type = 'IOT - TOP' and tablespace_name='SYSAUX';
Indexes
select 'alter index ' || do.owner || '.' || do.object_name || ' rebuild tablespace apex;' as cmd from dba_objects do, dba_segments ds, dba_indexes di where do.owner = 'SCOTT' and do.owner=ds.owner and do.owner=di.owner and do.object_type = 'INDEX' and di.index_type in('NORMAL', 'FUNCTION-BASED NORMAL') and do.object_name = ds.segment_name and do.object_name = di.index_name and ds.tablespace_name='SYSAUX';
Partitioned Indexes
Similar to Partitioned Tables but using alter index and referencing either DBA_INDEXES or DBA_IND_PARTITIONS
LOBS
LOBS on Non-partitioned Tables
select distinct 'alter table ' || dtc.owner || '.' || dtc.table_name || ' move lob(' || column_name || ')' || ' store as (tablespace DEF_TABLESPACE);' as cmd_to_invoke from dba_tab_columns dtc, dba_tables dt, dba_indexes di where dt.owner=dtc.owner and dt.owner=di.owner and dt.table_name=di.table_name and dt.table_name=dtc.table_name and dtc.owner = 'SCOTT' and dtc.data_type like '%LOB%' and di.index_name in (select segment_name from dba_segments inner where inner.owner=dt.owner and tablespace_name='SYSAUX') ;
LOBS on Partitioned Tables
select distinct 'alter table ' || dtc.owner || '.' || dtc.table_name || ' move partition ' || dt.partition_name || ' lob(' || column_name || ')' || ' store as (tablespace TARGET_TS)' || ';' from dba_tab_columns dtc, dba_tab_partitions dt, dba_indexes di where dt.table_owner=dtc.owner and dt.table_owner=di.owner and dt.table_name=di.table_name and dt.table_name=dtc.table_name and dtc.owner ='SCOTT' and dtc.data_type like '%LOB%' and di.index_name in (select segment_name from dba_segments inner where inner.owner=dt.table_owner and tablespace_name='SYSAUX')
Moving the user table in another tablespace
BEGIN
FOR i IN (
SELECT * FROM ALL_tables where owner = :owner
and (tablespace_name is null or tablespace_name != :tbs)
and temporary != 'Y'
and partitioned != 'YES'
) LOOP
EXECUTE IMMEDIATE 'ALTER TABLE ' || i.table_name || ' MOVE TABLESPACE ' || :tbs;
END LOOP;
END;
BEGIN
FOR i IN (
SELECT * FROM ALL_tab_partitions
WHERE table_owner = :owner and tablespace_name != :tbs
) LOOP
EXECUTE IMMEDIATE 'ALTER TABLE '
|| i.table_name || ' MOVE PARTITION '
|| i.partition_name ||' TABLESPACE '|| :tbs;
END LOOP;
END;
BEGIN
FOR i IN (
SELECT * FROM ALL_tables where owner = :owner and partitioned = 'YES'
) LOOP
EXECUTE IMMEDIATE 'ALTER TABLE '
|| i.table_name || ' MODIFY DEFAULT ATTRIBUTES TABLESPACE ' || :tbs;
END LOOP;
END;
BEGIN
FOR i IN (
SELECT * FROM ALL_Lobs WHERE owner = :owner
and (tablespace_name is null or tablespace_name != :tbs)
) LOOP
EXECUTE IMMEDIATE 'ALTER TABLE ' || i.table_name || ' MOVE TABLESPACE ' || :tbs;
END LOOP;
END;
Moving indexes to another user tablespace
BEGIN
FOR i IN (
SELECT * FROM ALL_indexes
where owner = :owner
and tablespace_name != :index_tbs
and index_type != 'IOT - TOP'
) LOOP
EXECUTE IMMEDIATE 'ALTER INDEX ' || i.index_name || ' REBUILD TABLESPACE ' || :index_tbs;
END LOOP;
END;
BEGIN
FOR i IN (
SELECT * FROM ALL_indexes
where owner = :owner
and partitioned = 'YES'
) LOOP
EXECUTE IMMEDIATE 'ALTER INDEX ' || i.index_name
|| ' MODIFY DEFAULT ATTRIBUTES TABLESPACE ' || :index_tbs;
END LOOP;
END;
BEGIN
FOR i IN (
SELECT * FROM ALL_ind_partitions
where index_owner = :owner
and tablespace_name != :index_tbs
) LOOP
EXECUTE IMMEDIATE 'ALTER INDEX '
|| i.index_name || ' REBUILD PARTITION '
|| i.partition_name || ' TABLESPACE ' || :index_tbs;
END LOOP;
END;
Moving Lob segment
BEGIN
FOR i IN (
select * from user_lobs where (tablespace_name is null or tablespace_name != :tbs)
) LOOP
EXECUTE IMMEDIATE 'ALTER TABLE ' || i.table_name || ' MOVE TABLESPACE ' || :tbs
|| ' LOB (' || i.column_name || ')'
|| ' STORE AS ' || i.segment_name || ' (TABLESPACE ' || :tbs ||' )';
END LOOP;