我有一个JPQL查询,可以正常使用MySQL和SQL Server。但是对于Oracle,它失败了
ORA-00932: inconsistent datatypes: expected - got CLOB
原因似乎是Oracle不支持带CLOB列的ORDER BY。
是否有任何JPQL解决此问题?
答案 0 :(得分:4)
您需要将CLOB转换为Varchar才能进行排序。不幸的是,Oracle中的Varchar列限制为4000个字符。如果按前4000个字符排序是合理的,这是使用DBMS_LOB.SUBSTR的SQLPlus示例:
SQL> create table mytable (testid int, sometext clob);
Table created.
SQL> insert into mytable values (1, rpad('z',4000,'z'));
1 row created.
SQL> update mytable set sometext = sometext || sometext || sometext;
1 row updated.
SQL> select length(sometext) from mytable;
LENGTH(SOMETEXT)
----------------
12000
SQL> select testid from mytable
2 order by dbms_lob.substr(sometext, 0, 4000);
TESTID
----------
1
SQL> drop table mytable;
Table dropped.