Dear friends,
I had a anoymous procedure for checking tablespace usage,
it can be run without problem. When I conver it to a store procedure, it have compilation error. Can anyone help me??
the anonymous procedure as follow (run on ora 8.1.6):
declare
name char(20);
mbytes char(20);
used char(20);
free char(20);
pct_used char(20);
cursor test_cur is
select a.tablespace_name name,
sum(b.bytes)/count( distinct a.file_id||'.'||a.block_id ) /
1048576 mbytes, round(((sum(b.bytes)/
count( distinct a.file_id||'.'||a.block_id ) -
sum(a.bytes)/count( distinct b.file_id ))/ 1048576),2) used,
round((sum(a.bytes)/count( distinct b.file_id ) /
1048576),2) free,
round(100 * ( (sum(b.bytes)/
count( distinct a.file_id||'.'||a.block_id ))
-(sum(a.bytes)/count( distinct b.file_id ) )) /
(sum(b.bytes)/count( distinct a.file_id||'.'||a.block_id )),2)
pct_used
from sys.dba_free_space a, sys.dba_data_files b
where a.tablespace_name = b.tablespace_name
group by a.tablespace_name, b.tablespace_name;
test_val test_cur%rowtype;
begin
open test_cur;
dbms_output.put_line('Table Space ' ||' '||
'mbytes ' ||' '||
'used ' ||' '||
'free ' ||' '||
'pct_used ');
dbms_output.put_line('--------------------------------------------------------------------------------------------------');
loop
fetch test_cur into test_val;
exit when test_cur%notfound;
name := test_val.name;
mbytes := test_val.mbytes;
used := test_val.used;
free := test_val.free;
pct_used := test_val.pct_used;
dbms_output.put_line(name ||' '|| mbytes ||' '|| used ||' '|| free ||' '|| pct_used);
end loop;
close test_cur;
end;
The store proc (with error) as follow:
create procedure dsp_space
AS
name char(20);
mbytes char(20);
used char(20);
free char(20);
pct_used char(20);
cursor test_cur is
select a.tablespace_name name,
sum(b.bytes)/count( distinct a.file_id||'.'||a.block_id ) /
1048576 mbytes, round(((sum(b.bytes)/
count( distinct a.file_id||'.'||a.block_id ) -
sum(a.bytes)/count( distinct b.file_id ))/ 1048576),2) used,
round((sum(a.bytes)/count( distinct b.file_id ) /
1048576),2) free,
round(100 * ( (sum(b.bytes)/
count( distinct a.file_id||'.'||a.block_id ))
-(sum(a.bytes)/count( distinct b.file_id ) )) /
(sum(b.bytes)/count( distinct a.file_id||'.'||a.block_id )),2)
pct_used
from sys.dba_free_space a, sys.dba_data_files b
where a.tablespace_name = b.tablespace_name
group by a.tablespace_name, b.tablespace_name;
test_val test_cur%rowtype;
begin
open test_cur;
dbms_output.put_line('Table Space ' ||' '||
'mbytes ' ||' '||
'used ' ||' '||
'free ' ||' '||
'pct_used ');
dbms_output.put_line('--------------------------------------------------------------------------------------------------');
loop
fetch test_cur into test_val;
exit when test_cur%notfound;
name := test_val.name;
mbytes := test_val.mbytes;
used := test_val.used;
free := test_val.free;
pct_used := test_val.pct_used;
dbms_output.put_line(name ||' '|| mbytes ||' '|| used ||' '|| free ||' '|| pct_used);
end loop;
close test_cur;
end;
/