oracle數據庫查詢clob字段(Querying oracle clob column)

工做中遇到此場景,google查詢到stackoverflow上的討論,獲得解答,使用內置函數dbms_lob.compare。討論以下: mysql

Question: sql

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

select * from aTable where aClobColumn = 'value'; app

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 post

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

Answer:  google

Yes, it's not allowed (this restriction does not affectCLOBs comparison in PL/SQL) spa

to use comparison operators like=,!=,<>and so on in SQL statements, when trying hibernate

to compare twoCLOBcolumns orCLOBcolumn 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 theCLOBdata type.

To avoid implicit conversion, the'value'literal can be explicitly converted to theCLOB

data type usingTO_CLOB()function and then pass in to thecompare()function:

 select * from aTable where dbms_lob.compare(aClobColumn, to_clob('value')) = 0
相關文章
相關標籤/搜索