oracle中in的个数要是超过1000就会报错,那么我们可以把它拆成一节一节的:
in(1,2) or in (3,4)
StringUtils.defaultIfEmpty的命名空间是:
import org.apache.commons.lang.StringUtils;
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);
//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 ('')");
}剩下的你懂得!!!!!