Vous êtes sur la page 1sur 2

create or replace function table_space_estimate(p_tablespace_name in varchar2,

p_avg_row_size
in number,
p_num_rows
in number,
p_pct_free
in number)
return number as
v_ub number;
v_ab number;
begin
sys.dbms_space.create_table_cost(tablespace_name => p_tablespace_name,
avg_row_size
=> p_avg_row_size,
row_count
=> p_num_rows,
pct_free
=> p_pct_free,
used_bytes
=> v_ub,
alloc_bytes
=> v_ab);
return v_ab;
exception
when others then
return null;
end;
===============
select j.*, trunc((est_mbytes - mbytes) / mbytes * 100) est_size_incr_pct, est_m
bytes-mbytes est_size_incr_mbytes
from (select g.*,
trunc(table_space_estimate(g.tablespace_name,
g.avg_row_len,
g.num_rows,
g.pct_free)/1024/1024) est_mbytes
from (select s.owner,
s.segment_name,
s.partition_name,
s.tablespace_name,
decode(segment_type, 'TABLE PARTITION', p.AVG_ROW_LEN, t.
AVG_ROW_LEN) avg_row_len,
decode(segment_type, 'TABLE PARTITION', p.NUM_ROWS, t.NUM
_ROWS) num_rows,
decode(segment_type, 'TABLE PARTITION', p.pct_free, t.pct
_free) pct_free,
decode(segment_type, 'TABLE PARTITION', p.last_analyzed,
t.last_analyzed) last_analyzed,
s.mbytes
from (select *
from (select tablespace_name,
owner,
segment_name,
trunc(bytes/1024/1024) mbytes,
segment_type,
a.partition_name
from dba_segments a
where segment_type in ('TABLE', 'TABLE PARTITIO
N')
and owner!='SYS'
order by bytes desc)
where rownum <= 500) s,
dba_tables t,
dba_tab_partitions p
where t.owner(+) = s.owner
and t.table_name(+) = s.segment_name
and p.table_owner(+) = s.owner
and p.table_name(+) = s.segment_name
and p.partition_name(+) = s.partition_name) g

order by mbytes desc) j order by est_mbytes-mbytes;