簡體   English   中英

如何 select 具有 CLOB 數據類型的列

[英]How to select a column in with a CLOB datatype

我的 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 代碼中,所以它可以在我的頁面中使用。

問題來自查詢的 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”的簡單谷歌搜索找到問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM