Caused by: java.sql.SQLException: ORA-01795: 列表中的最大運算式數為 1000解決方案

來源:互聯網
上載者:User

標籤:caused by java.sql.s

這個原因在於Oracle文法限制,in內數量必須小於1000,故採取滿1000分割用OR串連,下面是解決方案:

/**  * Example: List sqhlist=[''aa''"bb""cc""dd""ee""ff""gg"'] ;  * Test.getSqlStrByList(sqhList,3,"SHENQINGH")= "SHENQING IN  * ('aa','bb','cc') OR SHENQINGH IN ('dd','ee','ff') OR SHENQINGH IN ('g  *  * 把超過1000的in條件集合拆分成數量splitNum的多組sql的in 集合。  *  * @param sqhList  *            in條件的List  * @param splitNum  *            拆分的間隔數目,例如: 1000  * @param columnName  *            SQL中引用的欄位名例如: Z.SHENQINGH  * @return  **/private static String getSqlStrByList(List sqhList, int splitNum,String columnName) {if (splitNum > 1000) // 因為資料庫的列表sql限制,不能超過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()) {ids.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, 1000,"test");System.out.println(ss);}


Caused by: java.sql.SQLException: ORA-01795: 列表中的最大運算式數為 1000解決方案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.