【Oracle】查看带Lob字段的表大小
Oracle中,对表上的lob字段是单独存储的,所以使用segment_name = 表名的时候,只能统计非 lob 字段的数据大小,无法统计上lob字段的。
为了方面统计,在MOS上找到一篇参考文章:
How to Compute the Size of a Table containing Outline CLOBs and BLOBs (文档 ID 118531.1)
相关的SQL语句如下:
SELECT (SELECT SUM(S.BYTES) -- The Table Segment size FROM DBA_SEGMENTS S WHERE S.OWNER = UPPER('&SCHEMA') AND (S.SEGMENT_NAME = UPPER('&TABNAME'))) + (SELECT SUM(S.BYTES) -- The Lob Segment Size FROM DBA_SEGMENTS S, DBA_LOBS L WHERE S.OWNER = UPPER('&SCHEMA') AND (L.SEGMENT_NAME = S.SEGMENT_NAME AND L.TABLE_NAME = UPPER('&TABNAME') AND L.OWNER = UPPER('&SCHEMA'))) + (SELECT SUM(S.BYTES) -- The Lob Index size FROM DBA_SEGMENTS S, DBA_INDEXES I WHERE S.OWNER = UPPER('&SCHEMA') AND (I.INDEX_NAME = S.SEGMENT_NAME AND I.TABLE_NAME = UPPER('&TABNAME') AND INDEX_TYPE = 'LOB' AND I.OWNER = UPPER('&SCHEMA'))) "TOTAL TABLE SIZE" FROM DUAL;