在Oracle中,sql中in不能超过1000个,比如:select * from table t where t.id in (1,2,3,......1001,1002)
系统将报错,解决办法如下,写成两个或者多个。如:t.id in (1,2,....1000) or t.id in (1001,1002)
实现代码如下:
public String DivString(){
StringBuffer sb = new StringBuffer();
StringBuffer sb2 = new StringBuffer();
List agentList = new ArrayList();
for(int i =0;i<1100;i++)
agentList.add(i);
for(int i=0;i<agentList.size();i++){
if(i==agentList.size()-1)
sb.append("'").append(agentList.get(i)).append("')");
else if(i%1000==0&&i>0)
sb.append("'").append(agentList.get(i)).append("'")
.append(") or t.id in (");
else
sb.append("'").append(agentList.get(i)).append("',");
}
sb2.append(" t.id in ('',"+sb);
System.out.println("sql is: "+sb2.toString());
return sb2.toString();
}
posted on 2010-01-11 22:48
fly 阅读(3265)
评论(2) 编辑 收藏 所属分类:
数据库学习