- 论坛徽章:
- 0
|
急!!如何通过SQL得到表空间已经使用空间及其使用百分比
column tablespace_name format a18;
column Sum_M format a12;
column Used_M format a12;
column Free_M format a12;
column pto_M format 9.99;
select s.tablespace_name,ceil(sum(s.bytes/1024/1024))||'M' Sum_M,ceil(sum(s.UsedSpace/1024/1024))||'M' Used_M,ceil(sum(s.FreeSpace/1024/1024))||'M' Free_M, sum(s.FreeSpace)/sum(s.bytes) ptO
from ( select b.file_id,
b.tablespace_name,
b.bytes,
(b.bytes-sum(nvl(a.bytes,0))) UsedSpace,
sum(nvl(a.bytes,0)) FreeSpace,
(sum(nvl(a.bytes,0))/(b.bytes)) * 100 FreePercentRatio
from sys.dba_free_space a,sys.dba_data_files b
where a.file_id(+)=b.file_id
group by b.file_id,b.tablespace_name,b.bytes
order by b.tablespace_name
) s
group by s.tablespace_name
order by sum(s.FreeSpace)/sum(s.bytes) desc; |
|