Solutions for handling Oracle SQL in over 1000

Source: Internet
Author: User


Solutions for handling Oracle SQL in over 1000 ,..., 1000,100). If the clause contains more than 1000 entries, an error is returned. This is mainly because of oracle's restrictions on performance. If you want to solve the problem, you can use where id (1, 2 ,..., 1000) or id (1001 ,...) www.2cto.com [java]/*** <B> function: </B> process the in clause of an oracle SQL statement (where id in (1, 2 ,..., 1000,100 1), * if the clause contains more than 1000 items, an error is returned. * This is mainly a limitation on oracle's consideration of performance issues. * If you want to solve the problem, you can use where id (1, 2 ,..., 1000) or id (1001 ,...) * @ author hoojo * @ createDate 02:36:03 * @ param ids in the Set object * @ param count in the statement number of conditions * @ param field in the statement corresponding to the Database Query field * @ return returns field in (...) or field in (...) string */private String getOracleSQLIn (List <?> Ids, int count, String field) {count = Math. min (count, 1000); int len = ids. size (); int size = len % count; if (size = 0) {size = len/count;} else {www.2cto.com size = (len/count) + 1 ;} stringBuilder builder = new StringBuilder (); for (int I = 0; I <size; I ++) {int fromIndex = I * count; int toIndex = Math. min (fromIndex + count, len); // System. out. println (ids. subList (fromIndex, toIndex ); String productId = StringUtils. defaultIfEmpty (StringUtils. join (ids. subList (fromIndex, toIndex), "','"), ""); if (I! = 0) {builder. append ("or");} builder. append (field ). append ("in ('"). append (productId ). append ("')");} return StringUtils. defaultIfEmpty (builder. toString (), field + "in ('')");}

Related Article

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.