Problem : ora-22835 buffer too small for clob to char or blob to raw conversion

Problem : ora-22835 buffer too small for clob to char or blob to raw conversion

I am querying a view in Oracle 10g and received this error below:
ora-22835 buffer too small for clob to char or blob to raw conversion

The problematic field datatype is blob and I need to convert it to text to UNION several tables. I tried using DBMS_LOB.SUBSTR but still getting the same error. Any idea?


Solution: ora-22835 buffer too small for clob to char or blob to raw conversion

Cause
This is expected behavior becuase it is an unpublished Bug
in 10.1 (and 9i) due to which the conversion was truncated without warning or error.

However, in 10.2 this bug was fixed and so the truncation does not occur but also the varchar can
only hold 4000 bytes. In this case the clob is 5608 bytes and so the TO_CHAR cannot be performed and the error is expected.

Solution
Use DBMS_LOB.SUBSTR instead of TO_CHAR.
The DBMS_LOB.SUBSTR function returns a VARCHAR just like TO_CHAR, and you can limit the amount of data that you want to convert.