在Oracle中,sql中in不能超過1000個(gè),比如:select * from table t where t.id in (1,2,3,......1001,1002)
系統(tǒng)將報(bào)錯(cuò),解決辦法如下,寫成兩個(gè)或者多個(gè)。如:t.id in (1,2,....1000) or t.id in (1001,1002)
實(shí)現(xiàn)代碼如下:
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)
評(píng)論(2) 編輯 收藏 所屬分類:
數(shù)據(jù)庫學(xué)習(xí)