关于oracle查询用in不能超过1000条的解决办法

三个参数分别为:需要分割的List集合,截取每个的最大长度,字段名
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 {
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(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 ('')" );
}

你可能感兴趣的:(关于oracle查询用in不能超过1000条的解决办法)