简体   繁体   中英

How to select a column in with a CLOB datatype

I have a table on my jsp page that will have a column populated by a database column with type CLOB. I am running into some trouble doing this, and have seen other questions asked about this, but the answers have not worked for me. Here is my statement where comments is a 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();     

And then I will have the columns in a while loop:

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

So, basically, I was wondering if there is a way to translate the CLOB in the query, or even in the java code, so it would be usable in my page.

The problem comes from the distint clause of the query, which can't be applied to a CLOB.

Check if the distinct keyword is really needed. Or maybe you could rewrite your query as

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

PS: next time, include the error message and your database in the question. I've been able to find the problem with a simple google search on "ora-00932 clob".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM