ORACLE如何查看表空間存儲了那些數據庫對象呢?可以使用下面腳本簡單的查詢表空間存儲了那些對象:
SELECT TABLESPACE_NAME AS TABLESPACE_NAME
, SEGMENT_NAME AS SEGMENT_NAME
, SUM(BYTES)/1024/1024 AS SEGMENT_SIZE
FROM DBA_SEGMENTS
WHERE TABLESPACE_NAME=&TABLESPACE_NAME
GROUP BY TABLESPACE_NAME,SEGMENT_NAME
ORDER BY 3
如果你想了解一下對象的詳細信息,例如對象類型(表、索引)、對象的OWNER,可以使用下面SQL語句查詢
/*查詢表空間中對象的詳細信息*/
SELECT OWNER AS OWNER
,SEGMENT_NAME AS SEGMENT_NAME
,SEGMENT_TYPE AS SEGMENT_TYPE
,SUM(BYTES)/1024/1024 AS SEGMENT_SIZE
FROM DBA_SEGMENTS
WHERE TABLESPACE_NAME=&TABLESPACE_NAME
GROUP BY OWNER,SEGMENT_NAME,SEGMENT_TYPE
ORDER BY 4;
另外,也可以通過下面SQL語句查看表空間的對象
SELECT OWNER AS OWNER
,'TABLE' AS SEGMENT_TYPE
,TABLE_NAME AS SEGMENT_NAME
FROM DBA_TABLES
WHERE TABLESPACE_NAME=&TABLESPACE_NAME
UNION ALL
SELECT OWNER AS OWNER
,'INDEX' AS SEGMENT_TYPE
,INDEX_NAME AS SEGMETN_NAME
FROM DBA_INDEXES
WHERE TABLESPACE_NAME=&TABLESPACE_NAME
UNION ALL
SELECT OWNER AS OWNER
,'LOBSEGMENT' AS SGEMENT_TYPE
,SEGMENT_NAME AS SEGMENT_NAME
FROM DBA_LOBS
WHERE TABLESPACE_NAME=&TABLESPACE_NAME;