Join Method for SQL in statement up to 1000

Source: Internet
Author: User

The SQL in statement can be joined up to 1000. By default, Oracle supports 1000 in the number of in statements. This is also for SQL Performance processing, because in statements do not have good performance. In this case, it is best to use association queries for processing. If the associated query cannot implement your logic, discard the performance. Concatenate SQL statements. You can use or in to achieve (not recommended) the splicing method: Java code private static 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 {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); String productId = StringUtils. defaultIfEmpty (StringUtils. join (I Ds. 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.