Handle the Oracle SQL statement in clause (where ID in (1, 2, ..., 1000, 1001)), and if more than 1000 items in the clause will be an error. This is primarily a limitation that Oracle considers performance issues. If you want to solve the minor problem, you can use the where ID (1, 2, ..., +) or ID (1001, ...)
PackageWindy.learn;Importjava.util.Collection;Importorg.apache.commons.lang3.StringUtils; Public classOraclesqlutils {/*** x, y divide, rounding up *@paramx *@paramy *@returndivide x, y, rounding up*/ Private Static intCeildiv (intXinty) {intR = x/y; returnR * y = = x? R:r + 1; } Public StaticString Getoraclesqlin (collection<string>IDs, String field) { returnGetoraclesqlin (IDs, 1000, field); } /*** An error is found in the Oracle SQL statement in clause if more than 1000 items are in the clause. This is primarily a limitation that Oracle considers performance issues. If you want to solve the minor problem, you can use the * where ID (1, 2, ..., +) or ID (1001, ...) * * @paramCollection Object in the IDS * in statement *@paramnumber of conditions that appear in the count * in statement *@paramdatabase query fields corresponding to field * in statements *@returnreturns the field in (...) or field in (...) string*/ Public StaticString Getoraclesqlin (collection<string> IDs,intcount, String field) {string[] Idsarr= Ids.toarray (NewString[0]); Count= Math.min (count, 1000); intLen =idsarr.length; intSize =Ceildiv (Len, Count); StringBuilder Builder=NewStringBuilder (); for(inti = 0; i < size; i++) { intFromIndex = i *count; intToindex = math.min (FromIndex +count, Len); String productId=Stringutils.defaultifempty (Stringutils.join (Idsarr,"', '", FromIndex, Toindex), ""); if(I! = 0) {builder.append ("or"); } builder.append (field). Append ("In ('"). Append (ProductId). Append ("‘)"); } returnStringutils.defaultifempty (builder.tostring (), Field+ "in (')"); }}
Reference: http://www.cnblogs.com/hoojo/archive/2012/08/31/2665396.html
Handling Oracle SQL in over 1000 solutions