conn scott/tiger
DROP TABLE EMP1 PURGE;
CREATE TABLE EMP1 AS SELECT * FROM EMP;

alter table emp1 enable row movement; 
-- 启动回缩特性     
insert into emp1 select * from emp1; 
/
/

commit;
-- 增加到14000行

-- 分析表的结构     
analyze table emp1 compute statistics; 
select NUM_ROWS,BLOCKS,EMPTY_BLOCKS,AVG_SPACE from tabs where table_name='EMP1'; 
-- 查询高水位    
     
delete emp1 where deptno=30;
commit; 
-- 删除一半的数据     
analyze table emp1 compute statistics; 
-- 分析表的结构     
select NUM_ROWS,BLOCKS,EMPTY_BLOCKS,AVG_SPACE from tabs where table_name='EMP1'; 
-- 查询高水位     
SELECT DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) BLOCK#,COUNT(*) FROM EMP1
GROUP BY DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID); 
-- 查询块内行的分布     
SELECT EXTENT_ID,BLOCK_ID,BLOCKS FROM DBA_EXTENTS WHERE SEGMENT_NAME='EMP1'; 
-- 将数据挪动到表的前端,但不回缩高水位 
alter table EMP1 shrink space compact; 
-- 回缩高水位     
alter table EMP1 shrink space ; 

analyze table emp1 compute statistics; 
select NUM_ROWS,BLOCKS,EMPTY_BLOCKS,AVG_SPACE from tabs where table_name='EMP1';
该特性和压缩的特性冲突。

Oracle -在线回缩表-LMLPHP

05-14 12:50