Caused by:java.sql.sqlexception:ora-01795: The maximum number of expressions in the list is 1000 solution

Source: Internet
Author: User
Tags stringbuffer

This is due to the Oracle syntax constraints, in the number must be less than 1000, so take a full 1000 partition with or connected, the following is the solution:

/** * example:list sqhlist=[' aa ' "BB" "CC" "dd" "ee" "FF" "GG" ']; * Test.getsqlstrbylist (sqhlist,3, "shenqingh") = "shenqing" (' AA ', ' BB ', ' cc ') or Shenqingh in (' dd ', ' ee ', ' ff ') or ShenQi  NGH in (' g * * * splits more than 1000 of the in condition set into a set of multiple splitnum of SQL.            * * @param sqhlist * in condition list * @param splitnum * Split interval number, for example: $ * @param columnName * Field names referenced in SQL for example: Z.shenqingh * @return **/private static String getsqlstrbylist (List sqhlist, int splitnum,string Co Lumnname) {if (Splitnum > 1000)//Because the database has a list of SQL restrictions that cannot exceed 1000.return null;  StringBuffer ids = new StringBuffer (""); if (sqhlist! = null) {Ids.append (""). Append (ColumnName). Append ("in ("); for (int i = 0; I < sqhlist.size (); i++) {ids.append ("'"). Append (Sqhlist.get (i) + "'"), if ((i + 1)% Splitnum = = 0 && (i + 1) < Sqhlist.size ()) {ID S.deletecharat (Ids.length ()-1), Ids.append (") OR"). Append (ColumnName). Append ("in (");}} Ids.deletecharat (Ids.length ()-1); Ids.append (")");} Return Ids.tostriNg ();} public static void Main (string[] args) {List List = new ArrayList (); int id = 2;for (int i=0;i<1020;i++) {list.add ("'" +id+ "'");} String ss = getsqlstrbylist (list, N, "test"); SYSTEM.OUT.PRINTLN (ss);}


Caused by:java.sql.sqlexception:ora-01795: The maximum number of expressions in the list is 1000 solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.