查询oracle clob列

Dev*_*ked 25 sql database oracle hibernate jpa

我有一张带有clob柱的桌子.需要执行基于clob列内容的搜索.然而

select * from aTable where aClobColumn = 'value';

但失败了

select * from aTable where aClobColumn like 'value';
Run Code Online (Sandbox Code Playgroud)

似乎工作很精细.oracle如何处理clob列上的过滤.它是否只支持'like'子句而不支持=,!=等.它与其他数据库如mysql,postgres等是否相同

另外,在实现JPA的框架中如何处理这种情况,如hibernate?

Nic*_*nov 38

是的,这是不允许的(这个限制不会影响CLOB在PL/SQL小号比较)使用比较运营商如=,!=,<>等SQL语句,试图比较两个当CLOB列或CLOB列,字符文字,像你一样.为了能够在SQL语句中进行这样的比较,可以使用dbms_lob.compare()函数.

  select * 
    from aTable 
   where dbms_lob.compare(aClobColumn, 'value') = 0
Run Code Online (Sandbox Code Playgroud)

在上面的查询中,'value'文字将被隐式转换为CLOB数据类型.为避免隐式转换,'value'可以CLOB 使用TO_CLOB()函数将文字显式转换为数据类型,然后传入compare()函数:

  select * 
    from aTable 
   where dbms_lob.compare(aClobColumn, to_clob('value')) = 0
Run Code Online (Sandbox Code Playgroud)


小智 6

怎么样

select * from table_name where to_char(clob_column) ="test_string"
Run Code Online (Sandbox Code Playgroud)

  • `TO_CHAR()`仅适用于长度小于4000个字符的clob. (7认同)