0

hi i am fetching the data from db But I am getting this exception:

ora-01795 maximum number of expressions in a list is 1000 I checked that I have more than 2000 entries in the list passed to the query IN parameter.my code is as given below

  String id ="";
        sqlQueryBuff = sqlQueryBuff.append("t.id IN (");
        for (Iterator iterator = resultList.iterator(); iterator.hasNext(); ) {
             id = (String) iterator.next();

            if (iterator.hasNext())
                sqlQueryBuff.append(" '" + id + "' , ");
            else
                sqlQueryBuff.append(" '" + id + "' ) ");
        }
 query = session.createQuery(sqlQueryBuff.toString());
        List list =query.list();
    return list;

how can i resolve this issue thanks

vinay dhiman
  • 35
  • 1
  • 4
  • When you searched for the error code, what did you find? Oh, you were too *lazy* to search, huh? Duplicate of [ORA-01795: maximum number of expressions in a list is 1000 , how to split the string](http://stackoverflow.com/q/21672104/5221149) **and** [Is there a workaround for ORA-01795: maximum number of expressions in a list is 1000 error?](http://stackoverflow.com/q/17842453/5221149), and likely *many, many more*... – Andreas Oct 15 '16 at 20:39

1 Answers1

0

The poor mans approach is to break up the list of IDs into bunches of 999 entries at most and get the results in this bunches.

The better approach was was to use PreparedStatement and its addBatch() executeBatch() methods.

Timothy Truckle
  • 15,071
  • 2
  • 27
  • 51