0
点赞
收藏
分享

微信扫一扫

oracle報錯ORA-01795: 列表中的最大表达式数为 1000


1. 报错原因:IN后括号里的主键值超过1000上。

2. 解决方案:

Select * from tablename where col in (‘col1’,’col2’ ………)
如果in 后面的Item过多的话,超过1000就会出现这种错误。
解决方法是:
Select * from tablename where col in (‘col1’,’col2’ ………, ‘col1000’) or col in (‘col1001’, …………)

3. 实例

原逻辑:

if(!"".equals(allset) && !allset.equals("null")){
StringBuffer sb = new StringBuffer("(");
String[] arr = allset.split(",");
for(int j=0;j<arr.length;j++){
if(j>0){
sb.append(",");
}
sb.append("'"+arr[j]+"'");
}
sb.append(")");
String del_lassessindexp = "业务逻辑' "+" and indexcode in "+sb.toString();
System.out.println("del_lassessindexp ------> "+del_lassessindexp);
mMap.put(del_lassessindexp, "DELETE");
}

修改后的逻辑:

if(!"".equals(allset) && !allset.equals("null")){
StringBuffer sb = new StringBuffer("(");
String[] arr = allset.split(",");
if (arr.length > 1000) {
int inNum = 1; //已拼装IN条件数量
for(int j=0;j<arr.length;j++){
if(j>0 && inNum > 1){
sb.append(",");
}
if (inNum == 997 && j>0) {
sb.append("'"+arr[j]+"'");
sb.append(") OR indexcode in ( ");
inNum = 1;
} else {
sb.append("'"+arr[j]+"'");
inNum++;
}
}
sb.append("))");
String del_lassessindexp = "业务逻辑' "+"' and indextype = '"+mIndexType+
"' and (indexcode in "+sb.toString();

mMap.put(del_lassessindexp, "DELETE");
} else {
for(int j=0;j<arr.length;j++){
if(j>0){
sb.append(",");
}
sb.append("'"+arr[j]+"'");
}
sb.append(")");
String del_lassessindexp = "业务逻辑' "+"' and indextype = '"+mIndexType+"' and indexcode in "+sb.toString();

mMap.put(del_lassessindexp, "DELETE");
}

}


举报

相关推荐

0 条评论