Avatar of jasmeen kaur
jasmeen kaur
 asked on

Conversion of CLOB data type to varchar

Hi ,

One my column in database stores a large xml file which I have to extract
I tried the below query

select to_char(SUBSTR(cdata,0,4000)) from table1where xxx_ID= xxx

I get only 4000 characters obviously. ow can I get the whole data.

Thanks in advance!
SQL

Avatar of undefined
Last Comment
jasmeen kaur

8/22/2022 - Mon
Pawan Kumar

Please try this -

select to_char(SUBSTR(cdata,0)) from table1 where xxx_ID= xxx

Open in new window


The last length parameter is optional. If you skip that then you will all the data from the start position you have given.

You can read more about SUBSTR function from - https://www.techonthenet.com/oracle/functions/substr.php

Also if you need full data you DO NOT need substr. You need substr if you want to get some substring from a string.

select to_char(cdata) from table1 where xxx_ID= xxx

Open in new window

jasmeen kaur

ASKER
@Pawan:  I did try 1:select to_char(cdata) from table1 where xxx_ID= xxx got the below error:

ORA-22835: Buffer too small for CLOB to CHAR or BLOB to RAW conversion (actual: 8785, maximum: 4000)
22835. 00000 -  "Buffer too small for CLOB to CHAR or BLOB to RAW conversion (actual: %s, maximum: %s)"
*Cause:    An attempt was made to convert CLOB to CHAR or BLOB to RAW, where
           the LOB size was bigger than the buffer limit for CHAR and RAW
           types.
           Note that widths are reported in characters if character length
           semantics are in effect for the column, otherwise widths are
           reported in bytes.
*Action:   Do one of the following
           1. Make the LOB smaller before performing the conversion,
           for example, by using SUBSTR on CLOB
           2. Use DBMS_LOB.SUBSTR to convert CLOB to CHAR or BLOB to RAW.
Pawan Kumar

Sorry i missed that it is CLOB data type.

Please try this

select dbms_lob.substr(cdata,32767,1) from table1 where xxx_ID = xxx

Open in new window

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Pawan Kumar

Edited my last comment.
jasmeen kaur

ASKER
I got error:

ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 1
06502. 00000 -  "PL/SQL: numeric or value error%s"
*Cause:    
*Action:
Pawan Kumar

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
awking00

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
jasmeen kaur

ASKER
Thanks for our help