oracle应用之select in超过1000条报错解决方法
【摘要】 本博客介绍oracle select in超过1000条数据的解决方法,java框架是采用mybatis的,这可以说是一种比较常见的错误:select * from A where id in(...),oracle官方函数做了限定,in里的参数只能1000个,所以超过1000个参数就会报错,解决方法是将集合分为每个集合1000的小集合,然后用or拼起来select *...
本博客介绍oracle select in超过1000条数据的解决方法,java框架是采用mybatis的,这可以说是一种比较常见的错误:select * from A where id in(...),oracle官方函数做了限定,in里的参数只能1000个,所以超过1000个参数就会报错,解决方法是将集合分为每个集合1000的小集合,然后用or拼起来select * from A where id in(1,2,...,1000) or id in (1001,1002,2000)...,好的,根据这个sql,下面介绍一下orm空间为mybatis的项目里怎么解决
java代码只要获取参数进行集合拆分就可以:
举个例子,下面是一种方法
List<String> values = new ArrayList<String>();
String[] configSeqArray = StringUtils.split(configSeq,',');
for (String str : configSeqArray) {
values.add(str);
}
List<Collection<String>> configSeqs = CollectionUtil.splitCollection(values, 1000);
- 1
- 2
- 3
- 4
- 5
- 6
复制公司同事写的集合拆分的方法
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class CollectionUtils {
public static List<Collection<String>> splitCollection(Collection<String>values , int size) {
List<Collection<String>> result = new ArrayList<Collection<String>>();
if(values.size() <= size ){ result.add(values);
}else{ int count =0; Collection<String> subCollection= null; for(String s:values){ if(subCollection == null){ subColletion = new ArrayList<String>(); result.add(subColletion); } subCollection.add(s); count++; if(count == size){ count =0; subCollectiion = null; } }
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
Mybatis的代码:
select * from t_config_related
<where> <if test="configSeqs != null and configSeqs.size()>0 and configSeqs.get(0).size()>0"> <foreach collection="configSeqs" item="seqs" open="seq in" separator="or seq in"> <foreach collection="seqs" item="seq" open="(" close=")" separator=","> #{seq} </foreach> </foreach> </if>
</where>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
文章来源: smilenicky.blog.csdn.net,作者:smileNicky,版权归原作者所有,如需转载,请联系作者。
原文链接:smilenicky.blog.csdn.net/article/details/87922878
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)