Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query a CLOB column in Oracle

I'm trying to run a query that has a few columns that are a CLOB datatype. If i run the query like normal, all of those fields just have (CLOB) as the value.

I tried using DBMS_LOB.substr(column) and i get the error

ORA-06502: PL/SQL: numeric or value error: character string buffer too small 

How can i query the CLOB column?

like image 382
Catfish Avatar asked Sep 24 '10 19:09

Catfish


People also ask

How do I select a CLOB column in SQL?

When getting the substring of a CLOB column and using a query tool that has size/buffer restrictions sometimes you would need to set the BUFFER to a larger size. For example while using SQL Plus use the SET BUFFER 10000 to set it to 10000 as the default is 4000. Running the DBMS_LOB.

How do I read CLOB data?

You can read CLOB value (character stream data) from a table using getCharacterStream() or getClob() methods of the ResultSet interface. These methods accept an integer value representing the index of the required column (or, a String value representing its name) and, reads CLOB data from it.

How do I view CLOB data in Oracle SQL Developer?

select dbms_lob. substr(clob_filed, 1000000, 1) from exportlog; I run this sql in sql developer and sqlplus in command prompt. both always return NULL.


2 Answers

This works

select DBMS_LOB.substr(myColumn, 3000) from myTable 
like image 101
Chris Avatar answered Sep 22 '22 23:09

Chris


When getting the substring of a CLOB column and using a query tool that has size/buffer restrictions sometimes you would need to set the BUFFER to a larger size. For example while using SQL Plus use the SET BUFFER 10000 to set it to 10000 as the default is 4000.

Running the DBMS_LOB.substr command you can also specify the amount of characters you want to return and the offset from which. So using DBMS_LOB.substr(column, 3000) might restrict it to a small enough amount for the buffer.

See oracle documentation for more info on the substr command

      DBMS_LOB.SUBSTR (        lob_loc     IN    CLOB   CHARACTER SET ANY_CS,        amount      IN    INTEGER := 32767,        offset      IN    INTEGER := 1)       RETURN VARCHAR2 CHARACTER SET lob_loc%CHARSET;  
like image 33
mrjohn Avatar answered Sep 22 '22 23:09

mrjohn