在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 閱讀(3311)
評論(2) 編輯 收藏 所屬分類:
數據庫學習