-- To make use of the DBMS_SPACE package you have to wrap the procedures in 
-- procedures of your own. Here is an example of the DBMS_SPACE.UNUSED_SPACE
-- that outputs to screen.




create or replace PROCEDURE unused_space(segment_owner in varchar2,
                      segment_name  in varchar2,
                      segment_type  in varchar2)
IS
total_blocks              number;
total_bytes               number;
unused_blocks             number;
unused_bytes              number;
last_used_extent_file_id  number;
last_used_extent_block_id number;
last_used_block           number;
header_text  varchar2(500);
BEGIN 

dbms_space.unused_space ( segment_owner,
                         segment_name,
                         segment_type,
                         total_blocks,
                         total_bytes,
                         unused_blocks,
                         unused_bytes,
                         last_used_extent_file_id,
                         last_used_extent_block_id,
                         last_used_block);
dbms_output.put_line('------------------------------------------------------ 
 --'); 

header_text := 'UNUSED SPACE FOR ' || segment_owner || '.' || segment_name 
|| ', ' || segment_type;
dbms_output.put_line(header_text);
dbms_output.put_line('------------------------------------------------------ 
 --');
dbms_output.put('.............TOTAL BLOCKS: ');
dbms_output.put_line(lpad(total_blocks,10));
dbms_output.put('..............TOTAL BYTES: ');
dbms_output.put_line(lpad(total_bytes,10));
dbms_output.put('............UNUSED BLOCKS: ');
dbms_output.put_line(lpad(unused_blocks,10));
dbms_output.put('.............UNUSED BYTES: ');
dbms_output.put_line(lpad(unused_bytes,10));
dbms_output.put('.LAST USED EXTENT FILE ID: ');
dbms_output.put_line(lpad(last_used_extent_file_id,10));
dbms_output.put('LAST USED EXTENT BLOCK ID: ');
dbms_output.put_line(lpad(last_used_extent_block_id,10));
dbms_output.put('..........LAST USED BLOCK: ');
dbms_output.put_line(lpad(last_used_block,10));
end;
/