SELECT UPPER(D.TABLESPACE_NAME) "Tablespace_name",
D.TOT_GROOTTE_MB - nvl(F.TOTAL_BYTES,0) "Used(M)", D.TOT_GROOTTE_MB "Tablespace_size(M)", TO_CHAR(ROUND((D.TOT_GROOTTE_MB - nvl(F.TOTAL_BYTES,0)) / D.TOT_GROOTTE_MB * 100, 2), '990.99') || '%' "Used%", nvl(F.TOTAL_BYTES,0) "Available_size(M)", decode(D.TOT_MAXBYTES_MB, 0, D.TOT_GROOTTE_MB, D.TOT_MAXBYTES_MB) "Max_Tablespace_size(M)", decode(D.TOT_MAXBYTES_MB, 0, TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_GROOTTE_MB * 100, 2), '990.99') || '%', TO_CHAR(ROUND(((D.TOT_GROOTTE_MB - F.TOTAL_BYTES)) / D.TOT_MAXBYTES_MB * 100, 2), '990.99') || '%') "Max_Used%", decode(D.TOT_MAXBYTES_MB, 0, D.TOT_GROOTTE_MB, D.TOT_MAXBYTES_MB) - (D.TOT_GROOTTE_MB - nvl(F.TOTAL_BYTES,0)) "Max_Available_size(M)" FROM (SELECT TABLESPACE_NAME, ROUND(SUM(BYTES) / (1024 * 1024), 2) TOTAL_BYTES FROM SYS.DBA_FREE_SPACE GROUP BY TABLESPACE_NAME) F, (SELECT DD.TABLESPACE_NAME, ROUND(SUM(DD.BYTES) / (1024 * 1024), 2) TOT_GROOTTE_MB, ROUND(SUM( decode(DD.MAXBYTES,0,DD.BYTES,DD.MAXBYTES)) / (1024 * 1024), 2) TOT_MAXBYTES_MB FROM SYS.DBA_DATA_FILES DD GROUP BY DD.TABLESPACE_NAME) D WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME(+) ORDER BY decode(D.TOT_MAXBYTES_MB, 0, TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_GROOTTE_MB * 100, 2), '990.99') || '%', TO_CHAR(ROUND(((D.TOT_GROOTTE_MB - F.TOTAL_BYTES)) / D.TOT_MAXBYTES_MB * 100, 2), '990.99') || '%') desc;