將用戶當前表空間中的表和索引遷移到另外一個表空間

查看INV用戶的對象的存儲狀況
select * from dba_segments ds where ds.owner='INV';
--default tablespace users

建立表空間INV
create tablespace inv datafile '/oradata/ocm/inv01.dbf ' size 200M autoextend on next 10m maxsize 2048M extent management local segment space management auto;
設置默認表空間爲INV
alter user inv default tablespace inv;


set linesize 200
set pagesize 2000
set term off verify off head off feedback off echo off

spool mtiddl.sql

select 'alter ' ||ds.segment_type || ' '|| ds.owner||'.' || ds.segment_name || ' ' ||
       decode(segment_type, 'TABLE', 'MOVE', 'INDEX', 'REBUILD') ||
       ' tablespace INV;'
  from dba_segments ds
 where ds.owner = 'INV'
   AND (segment_type = 'INDEX' OR segment_type = 'TABLE');

spool offsql

相關文章
相關標籤/搜索