Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying CLOB Column with 4000+ characters

Tags:

oracle

clob

I have this CLOB column and I need to display it using a select statement.

I used DBMS_LOB.SUBSTR to convert it to varchar2:

select DBMS_LOB.SUBSTR(T1.CLOB_COL,4000,1) CLOB_COL from T1

My problem is some of my CLOBS contains more than 4000 characters. How can I display it...any idea/suggestion?

thanks a lot..

like image 405
pein Asd Avatar asked Sep 09 '11 06:09

pein Asd


People also ask

How many characters can a CLOB hold?

A CLOB (character large object) value can be up to 2,147,483,647 characters long.

How do you determine the size of a CLOB column?

GetLength – Find the size of BLOB/CLOB column. This is simply how to find the size of individual rows with the CLOB/BLOB column. DBMS_LOB. GetLength returns the number of characters (bytes) in the CLOB/BLOB column.


1 Answers

I guess you could display the chunks as separate rows ?

SELECT ROWNUM as chunk_no,ID, SUBSTR (t1.clob_col, (ROWNUM-1)*4000, 4000) AS chunk
FROM t1
CONNECT BY (ROWNUM-1)*4000 <= LENGTH(t1.clob_col)

or if there is a constraint on the maximum size a clob could be in your system you could hard code the number of text columns returned

SELECT SUBSTR (t1.clob_col, 1, 4000) AS pt1,
       CASE WHEN LENGTH (t1.clob_col) > 4000  THEN SUBSTR (t1.clob_col, 4001, 4000) END AS pt2,
       CASE WHEN LENGTH (t1.clob_col) > 8000  THEN SUBSTR (t1.clob_col, 8001, 4000) END AS pt3,
       CASE WHEN LENGTH (t1.clob_col) > 12000 THEN SUBSTR (t1.clob_col, 1201, 4000) END AS pt4
FROM t1
like image 143
Kevin Burton Avatar answered Oct 23 '22 03:10

Kevin Burton