SELECT
a.tablespace_name 表空间名称,
total 总计,
total - free 已使用,
free 空闲,
round((total - free) / total * 100, 2) 使用占比
FROM (
SELECT tablespace_name
, round(SUM(bytes) / 1024 / 1024) AS total
FROM dba_data_files
GROUP BY tablespace_name
) a
LEFT JOIN (
SELECT tablespace_name
, round(SUM(bytes) / 1024 / 1024) AS free
FROM dba_free_space
GROUP BY tablespace_name
) b
ON a.tablespace_name = b.tablespace_name
ORDER BY (total - free) / total DESC;