在PL/SQL中查看表空間使用情況,可以通過以下步驟進行:
SELECT tablespace_name,
SUM(bytes) / 1024 / 1024 AS total_size_mb,
SUM(bytes - NVL(free_bytes, 0)) / 1024 / 1024 AS used_size_mb,
NVL(free_bytes, 0) / 1024 / 1024 AS free_size_mb,
round((SUM(bytes - NVL(free_bytes, 0)) / SUM(bytes)) * 100, 2) AS used_pct
FROM (SELECT tablespace_name, sum(bytes) AS bytes
FROM dba_data_files
GROUP BY tablespace_name
UNION ALL
SELECT tablespace_name, sum(bytes) AS bytes
FROM dba_temp_files
GROUP BY tablespace_name
UNION ALL
SELECT tablespace_name, sum(bytes) AS free_bytes
FROM dba_free_space
GROUP BY tablespace_name)
GROUP BY tablespace_name, free_bytes
ORDER BY tablespace_name;
通過以上查詢語句,您可以方便地查看數據庫中所有表空間的使用情況,幫助您管理和優化表空間的存儲空間。