我们都知道,当尝试使用超过1000个值的bomabard查询时,我们会看到此异常。列限制的最大值是1000 ..最好的解决方案是将查询拆分为两个。你可以建议一些可能的代码重构方法,以使我的问题消失。任何帮助将不胜感激。
当 audTypeFieldIdList 大于1000个值时,我们会看到异常。
try {
String query = "select AUDIT_TYPE_FIELD_ID, FIELD_NAME from AUDIT_TYPE_FIELD where AUDIT_TYPE_FIELD_ID in (";
int x = 0;
for (int y = 1; y <= audTypeFieldIdList.size(); y++) {
query += audTypeFieldIdList.get(x);
if (y != audTypeFieldIdList.size()) {
query += ", ";
}
x++;
}
query += ")";
List<Long> audTypeFieldIdList, Connection connection) {
ResultSet rs = null;
Statement stmt = null;
List<AuditTypeField> audTypeFieldList = new ArrayList<AuditTypeField>();
try {
String query = "select AUDIT_TYPE_FIELD_ID, FIELD_NAME from AUDIT_TYPE_FIELD where AUDIT_TYPE_FIELD_ID in (";
int x = 0;
for (int y = 1; y <= audTypeFieldIdList.size(); y++) {
query += audTypeFieldIdList.get(x);
if (y != audTypeFieldIdList.size()) {
query += ", ";
}
x++;
}
query += ")";
stmt = connection.createStatement();
rs = stmt.executeQuery(query);
while (rs != null && rs.next()) {
AuditTypeField audTypeField = PluginSystem.INSTANCE
.getPluginInjector().getInstance(AuditTypeField.class);
audTypeField.setId(rs.getLong("AUDIT_TYPE_FIELD_ID"));
audTypeField.setName(rs.getString("FIELD_NAME"));
audTypeFieldList.add(audTypeField);
}
return audTypeFieldList;
return audTypeFieldList;
答案 0 :(得分:5)
IN
子句中不能使用超过1000个条目。有两种解决方案如下所述:
使用inner query
解决此问题。您可以创建一个临时表,并在IN
子句中使用它。
使用由IN
子句分隔的多个OR
子句在1000个条目的批处理中打破它。
示例查询:
select * from table_name
where
column_name in (V1,V2,V3,...V1000)
or
column_name in (V1001,V1002,V1003,...V2000)
...