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 ?
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.
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.
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.
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.
Yes, it's not allowed (this restriction does not affect CLOB
s 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
how about
select * from table_name where to_char(clob_column) ="test_string"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With