05.11.2015 Views

Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

xl<br />

■SETTING UP YOUR ENVIRONMENT<br />

l_fs2_blocks number; l_fs2_bytes number;<br />

l_fs3_blocks number; l_fs3_bytes number;<br />

l_fs4_blocks number; l_fs4_bytes number;<br />

l_full_blocks number; l_full_bytes number;<br />

-- inline procedure to print out numbers nicely formatted<br />

-- with a simple label<br />

procedure p( p_label in varchar2, p_num in number )<br />

is<br />

begin<br />

dbms_output.put_line( rpad(p_label,40,'.') ||<br />

to_char(p_num,'999,999,999,999') );<br />

end;<br />

begin<br />

-- this query is executed dynamically in order to allow this procedure<br />

-- to be created by a user who has access to DBA_SEGMENTS/TABLESPACES<br />

-- via a role as is customary.<br />

-- NOTE: at runtime, the invoker MUST have access to these two<br />

-- views!<br />

-- this query determines if the object is an ASSM object or not<br />

begin<br />

execute immediate<br />

'select ts.segment_space_management<br />

from dba_segments seg, dba_tablespaces ts<br />

where seg.segment_name = :p_segname<br />

<strong>and</strong> (:p_partition is null or<br />

seg.partition_name = :p_partition)<br />

<strong>and</strong> seg.owner = :p_owner<br />

<strong>and</strong> seg.tablespace_name = ts.tablespace_name'<br />

into l_segment_space_mgmt<br />

using p_segname, p_partition, p_partition, p_owner;<br />

exception<br />

when too_many_rows then<br />

dbms_output.put_line<br />

( 'This must be a partitioned table, use p_partition => ');<br />

return;<br />

end;<br />

-- if the object is in an ASSM tablespace, we must use this API<br />

-- call to get space information, otherwise we use the FREE_BLOCKS<br />

-- API for the user-managed segments<br />

if l_segment_space_mgmt = 'AUTO'<br />

then<br />

dbms_space.space_usage<br />

( p_owner, p_segname, p_type, l_unformatted_blocks,<br />

l_unformatted_bytes, l_fs1_blocks, l_fs1_bytes,

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!