可以使用如下方法查碎片:
select bytes from dba_free_space;
可以采用如下方法查系统中物理上不连续的碎片:
create table wg_dba_free_space
as select * from dba_free_spacewhere 1=2;
create table wg_free_space as select file_id,block_id,blocks from dba_free_space;
create or replace procedure sp_freespace_wg
/*目的是找出系统中物理上不连续的碎片个数;而通过select count(*) from dba_free_space中得到的数目减去它计算出来的东西,就是可以通过coalesce命令整理的碎片数了。*/
is
p_file_id number;
p_block_id number;
p_blocks number;
pre_block_id number;
pre_blocks number;
pre_file_id number;
cursor c1 is
select file_id,block_id,blocks
from wg_dba_free_space
where tablespace_name='TS_BILL1'
order by file_id asc,block_id asc;
begin
p_file_id:=0;
p_block_id:=0;
p_blocks:=0;
pre_block_id:=0;
pre_file_id:=0;
for dba_data_files_rec in c1 LOOP
p_file_id:=dba_data_files_rec.file_id;
p_block_id:=dba_data_files_rec.block_id;
p_blocks:=dba_data_files_rec.blocks;
if (p_file_id=pre_file_id) and (p_block_id=pre_block_id+p_blocks) then
/*update*/
update wg_free_space set
blocks=blocks+p_blocks
where file_id=p_file_id
and block_id=p_block_id;
else
insert into wg_free_space(file_id,block_id,blocks)
values(p_file_id,p_block_id,p_blocks);
end if;
pre_file_id:=p_file_id;
pre_block_id:=p_block_id;
pre_blocks:=p_blocks;
commit;
end loop;
end;
execute sp_freespace_wg;