在上篇ORACLE查看表空间对象中,我介绍了如何查询一个表空间有那些数据库对象,那么我们是否可以查看某个数据文件包含那些数据库对象呢?如下所示
SELECT E.SEGMENT_TYPE AS SEGMENT_TYPE
, E.SEGMENT_NAME AS SEGMENT_NAME
, F.FILE_NAME AS FILE_NAME
, SUM(E.BYTES)/1024/1024 AS SEGMENT_SIZE
FROM DBA_EXTENTS E
INNER JOIN DBA_DATA_FILES F ON E.FILE_ID= F.FILE_ID
WHERE F.FILE_ID =109
GROUP BY E.SEGMENT_TYPE,E.SEGMENT_NAME,F.FILE_NAME
ORDER BY 4 DESC;
SELECT E.SEGMENT_TYPE AS SEGMENT_TYPE
, E.SEGMENT_NAME AS SEGMENT_NAME
, F.FILE_NAME AS FILE_NAME
, SUM(E.BYTES)/1024/1024 AS SEGMENT_SIZE
FROM DBA_EXTENTS E
INNER JOIN DBA_DATA_FILES F ON E.FILE_ID= F.FILE_ID
WHERE F.FILE_NAME =&FILE_NAME
GROUP BY E.SEGMENT_TYPE,E.SEGMENT_NAME,F.FILE_NAME
ORDER BY 4 DESC;
错误的写法,如下所示,DBA_SEGMENTS的HEADER_FILE表示ID of the file containing the segment header,主要是因为仅仅包含段对象的段头所在的文件。
SELECT ds.OWNER AS OWNER
,df.FILE_NAME AS FILE_NAME
,ds.SEGMENT_NAME AS SEGMENT_NAME
,ds.SEGMENT_TYPE AS SEGMENT_TYPE
,SUM(ds.BYTES)/1024/1024 AS SEGMENT_SIZE
FROM DBA_SEGMENTS ds
LEFT JOIN DBA_DATA_FILES df ON ds.HEADER_FILE = df.FILE_ID
WHERE ds.TABLESPACE_NAME=&TABLESPACE_NAME
AND df.FILE_ID=&FILE_ID
GROUP BY OWNER,FILE_NAME,SEGMENT_NAME,SEGMENT_TYPE
ORDER BY 4;
内容来源于网络如有侵权请私信删除
文章来源: 博客园
- 还没有人评论,欢迎说说您的想法!