ORACLE查看表空间对象

时间:2021-10-24 18:51:20

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;