Wednesday, 14 September 2011

Oracle: Get the size of a CLOB column

Assume the table structure is as below:

Table Name: Table_A
Column        Datatype
XMLID           NUMBER
XMLDATA      CLOB

Sample Records/Data:
XMLID   XMLDATA
123        Some text1 stored in CLOB
135        Some text2 stored in CLOB
  

1. If output of size of CLOB column needed in bytes:
SQL>  SELECT XMLID, DBMS_LOB.GETLENGTH(XMLDATA) AS SIZE_IN_BYTES FROM TABLE_A;

Output:
XMLID      SIZE_IN_BYTES
--------      -----------------------
123          25
135          25


2. If output of size of CLOB column needed in kilo bytes (KB) by rounding it off to two decimal places:
SQL>  SELECT XMLID, ROUND(DBMS_LOB.GETLENGTH(XMLDATA) / 1024, 2) AS SIZE_IN_KB FROM TABLE_A;
 
Output:
XMLID      SIZE_IN_KB
--------      --------------------
123          .02
135          .02