Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Querying oracle clob column

I have a table with a clob column. Searching based on the clob column content needs to be performed. However

select * from aTable where aClobColumn = 'value';

fails but

select * from aTable where aClobColumn like 'value'; 

seems to workfine. How does oracle handle filtering on a clob column. Does it support only the 'like' clause and not the =,!= etc. Is it the same with other databases like mysql, postgres etc

Also how is this scenario handled in frameworks that implement JPA like hibernate ?

like image 249
Dev Blanked Avatar asked Aug 15 '13 09:08

Dev Blanked


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 you query 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.

How do you read a CLOB object?

To read from a CLOB, use the getAsciiStream() or getCharacterStream() method of an oracle. sql. CLOB object to retrieve the entire CLOB as an input stream. The getAsciiStream() method returns an ASCII input stream in a java.

How do I search in CLOB?

CLOBs require that you use the DBMS_LOB package to perform substr/instr type searches. In order to use do any kind of searching within the column, you must first get the locator for the CLOB column, the use the DBMS_LOB. SUBSTR or DBMS_LOB. INSTR function to search and/or pull part of the text from the string.


Video Answer


2 Answers

Yes, it's not allowed (this restriction does not affect CLOBs comparison in PL/SQL) to use comparison operators like =, !=, <> and so on in SQL statements, when trying to compare two CLOB columns or CLOB column and a character literal, like you do. To be able to do such comparison in SQL statements, dbms_lob.compare() function can be used.

  select *      from aTable     where dbms_lob.compare(aClobColumn, 'value') = 0 

In the above query, the 'value' literal will be implicitly converted to the CLOB data type. To avoid implicit conversion, the 'value' literal can be explicitly converted to the CLOB data type using TO_CLOB() function and then pass in to the compare() function:

  select *      from aTable     where dbms_lob.compare(aClobColumn, to_clob('value')) = 0 
like image 164
Nick Krasnov Avatar answered Sep 23 '22 12:09

Nick Krasnov


how about

select * from table_name where to_char(clob_column) ="test_string" 
like image 39
Manish Puri Avatar answered Sep 22 '22 12:09

Manish Puri