SELECT "TABLESPACE_NAME",
"PCT_USED" as "PCT_USED(%)",
"ALLOCATED" as "ALLOCATED(mb)",
"USED" as "USED(mb)",
"FREE" as "FREE(%)",
"DATAFILES"
FROM (SELECT a.tablespace_name,
ROUND(((c.bytes - nvl(b.bytes, 0)) / c.bytes) * 100, 2) PCT_USED,
c.bytes / 1024 / 1024 allocated,
round(c.bytes / 1024 / 1024 - nvl(b.bytes, 0) / 1024 / 1024,
2) used,
round(nvl(b.bytes, 0) / 1024 / 1024, 2) free,
c.datafiles
FROM dba_tablespaces a,
(SELECT tablespace_name, SUM(bytes) bytes
FROM dba_free_space
GROUP BY tablespace_name) b,
(select count(1) datafiles, SUM(bytes) bytes, tablespace_name
from dba_data_files
GROUP BY tablespace_name) c
WHERE b.tablespace_name(+) = a.tablespace_name
AND c.tablespace_name(+) = a.tablespace_name
ORDER BY nvl(((c.bytes - nvl(b.bytes, 0)) / c.bytes), 0) DESC)
"PCT_USED" as "PCT_USED(%)",
"ALLOCATED" as "ALLOCATED(mb)",
"USED" as "USED(mb)",
"FREE" as "FREE(%)",
"DATAFILES"
FROM (SELECT a.tablespace_name,
ROUND(((c.bytes - nvl(b.bytes, 0)) / c.bytes) * 100, 2) PCT_USED,
c.bytes / 1024 / 1024 allocated,
round(c.bytes / 1024 / 1024 - nvl(b.bytes, 0) / 1024 / 1024,
2) used,
round(nvl(b.bytes, 0) / 1024 / 1024, 2) free,
c.datafiles
FROM dba_tablespaces a,
(SELECT tablespace_name, SUM(bytes) bytes
FROM dba_free_space
GROUP BY tablespace_name) b,
(select count(1) datafiles, SUM(bytes) bytes, tablespace_name
from dba_data_files
GROUP BY tablespace_name) c
WHERE b.tablespace_name(+) = a.tablespace_name
AND c.tablespace_name(+) = a.tablespace_name
ORDER BY nvl(((c.bytes - nvl(b.bytes, 0)) / c.bytes), 0) DESC)