0

我的 jsp 页面上有一个表,其中有一列由 CLOB 类型的数据库列填充。我在执行此操作时遇到了一些麻烦,并且看到了其他有关此问题的问题,但答案对我不起作用。这是我的声明,其中评论是 CLOB。

   stmt = conn.prepareStatement("SELECT DISTINCT restriction, person, start_date, end_date, comments "
                           + "  FROM restrictions WHERE person = ? "
                           + "   AND (start_date BETWEEN TO_DATE (? , 'yyyy/mm/dd') AND TO_DATE (? , 'yyyy/mm/dd') "
                           + "    OR start_date < TO_DATE (? , 'yyyy/mm/dd') AND end_date IS NULL) " );

        stmt.setString(1, Id);
        stmt.setString(2, StartRest);
        stmt.setString(3, EndRest);
        stmt.setString(4, EndRest);
        result = stmt.executeQuery();     

然后我将在 while 循环中有列:

   while (result.next()) {     
        restrictions = StringUtils.defaultString(result.getString("str_restriction"));
        .......
        // here is where I would get my Clob data from the query.

所以,基本上,我想知道是否有办法在查询中翻译 CLOB,甚至在 java 代码中,这样它就可以在我的页面中使用。

4

1 回答 1

2

问题来自查询的 distint 子句,它不能应用于 CLOB。

检查是否真的需要 distinct 关键字。或者,也许您可​​以将查询重写为

select restriction, person, start_date, end_date, comments from restrictions 
where id in (select distinct id from restrictions where <original where clause>)

PS:下次,在问题中包含错误消息和您的数据库。我已经能够通过对“ora-00932 clob”的简单谷歌搜索找到问题。

于 2011-07-05T17:07:26.117 回答