查询Oracle 数据库中带有lob字段的某一个表的大小

注意:由于lob字段有独立的lob segment来存储,故对于带有lob字段的表,不能仅仅查询dba_segments.

以下脚本来自:

How to Compute the Size of a Table containing Outline CLOBs and BLOBs[Article ID 118531.1]

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

经过修改:改为了NVL(SUM(S.BYTES),0)

SQL> col "TOTAL TABLE SIZE" format 99999999999999

---注意:以下sql可以直接执行。为了方便复制该脚本,因此不贴SQL语句的log,而是放上了执行时的SQL语句。

  1. SELECT
  2. (SELECT NVL(SUM(S.BYTES),0) -- The Table Segment size
  3. FROM DBA_SEGMENTS S
  4. WHERE S.OWNER = UPPER('LC0019999') AND
  5. (S.SEGMENT_NAME = UPPER('ZWPZK'))) +
  6. (SELECT NVL(SUM(S.BYTES),0) -- The Lob Segment Size
  7. FROM DBA_SEGMENTS S, DBA_LOBS L
  8. WHERE S.OWNER = UPPER('LC0019999') AND
  9. (L.SEGMENT_NAME = S.SEGMENT_NAME AND L.TABLE_NAME = UPPER('ZWPZK') AND L.OWNER = UPPER('LC0019999'))) +
  10. (SELECT NVL(SUM(S.BYTES),0) -- The Lob Index size
  11. FROM DBA_SEGMENTS S, DBA_INDEXES I
  12. WHERE S.OWNER = UPPER('LC0019999') AND
  13. (I.INDEX_NAME = S.SEGMENT_NAME AND I.TABLE_NAME = UPPER('ZWPZK') AND INDEX_TYPE = 'LOB' AND I.OWNER = UPPER('LC0019999')))
  14. "TOTAL TABLE SIZE"
  15. FROM DUAL;
  16. TOTAL TABLE SIZE
  17. ----------------
  18. 3571869286
  19. SQL> select 3571869286/1024/1024/1024 from dual;
  20. 35718692864/1024/1024/1024
  21. --------------------------
  22. 3.3265625

相关推荐