注:本文出自:博主自己研究验证可行

 

[原著]java或者Js  代码逻辑来处理  突破 oracle  sql “IN”长度的极限的问题

   在很多的时候 使用 select  *  from  tab_name t where  t.id in (1,2…………1000) ;  的固定方式来查询数据的时候。会有一种这个情况出现:

则是 in 里面的内容 太长了; 而 oracle数据库支持的长度是 100个内容。

         那么对于这个情况该怎么办呢。其实是很简单的,in 本身就是  所有 内容的or查询。

         对于此的办法是:把in的里面的参数给拆分成很多个。

        具体实现如下:

1:java 代码的实现:

  1  public List stapleToCzgkzxNew(DaoFactory daoFactory,String orgType, List lstSource ,List lstVo_jjfl) throws SQLException, Exception {
2
3 List lstTarget = new ArrayList();
4
5 try {
6 /**
7 * 需要 进行 经济分类 辅助核算
8 */
9 List lstIds_jjfl = new ArrayList();
10 //取出 集合中的 id
11 if(lstVo_jjfl.size()>0){
12 Iterator itSource_jjfl = lstVo_jjfl.iterator();
13 while (itSource_jjfl.hasNext()) {
14 ZfpzVO vo = (ZfpzVO) itSource_jjfl.next();
15 lstIds_jjfl.add(String.valueOf(vo.getGk_zfpz_id()));
16 }
17 //---start 20180315 新增 -------目的:提高生成数据执行速度,按照凭证号来查询数据。取消掉相同数据的合并问题---------------------
18 //把 id 拼接成字符串 1,2,3,4,5,6
19 int listLentgh=lstIds_jjfl.size();
20 int intFalg=50;//in 里面包含值的阀值
21 List lsId=new ArrayList();//存放id字符串集合
22 String stra="";
23 for (int i=0;i<listLentgh;i++){
24 if(i%intFalg == 0 && i != 0 ){
25 lsId.add(stra);
26 stra="";
27 }
28 if(i%intFalg == 0 ){
29 stra = ""+lstIds_jjfl.get(i);
30 }else{
31 stra = stra+","+lstIds_jjfl.get(i);
32 }
33 if(i+1==listLentgh && ( listLentgh !=1 &&i%intFalg != 0)){
34 lsId.add(stra);
35 } else if(i+1==listLentgh && listLentgh ==1 && i%intFalg == 0 ){
36 lsId.add(stra);
37 }
38 }
39 //---end 20180315 新增 ----------------------------
40
41
42 //---start 20180315 修改 -------目的:提高生成数据执行速度---------------------
43 List Gkzfpz_jjflList =ZwvchCommonHelper.factory().getGkzfpz_jjflList(daoFactory, lsId,orgType);
44 }
45
46 //下面是拼接 sql 的逻辑处理
47
48
49 */
50 public List getGkzfpz_jjflList (DaoFactory daoFactory, List lstZfpzId,String orgType){
51 String strSQL ="select * from view_k3_zfzxz_zfpz v WHERE 1 = 1 ";
52 List<Map<String, Object>>lstZfpz = new ArrayList();
53
54 try {
55
56 if(lstZfpzId.size()>0) {
57 strSQL += " AND ( ";
58 for (int index=0 ;index <lstZfpzId.size();index ++) {
59 if(index == 0){
60 strSQL += " v.id in ("+lstZfpzId.get(index)+")";
61 }else {
62 strSQL += " OR v.id in ("+lstZfpzId.get(index)+")";
63 }
64
65 }
66 strSQL += ")";
67 }
68 log.info("_______国库支付中心账务:直接支付凭证 ___________strSQL="+strSQL);
69 lstZfpz = daoFactory.getDao().getJdbcTemplate().queryForList(strSQL);
70 for(int i=0;i<lstZfpz.size();i++){
71 lstZfpz.get(i).put("org_type",orgType);
72 }
73 log.info("_______国库支付中心账务:直接支付凭证 ___________查询结果="+lstZfpz.size()+";======:"+lstZfpz.toString()) ;
74
75 } catch (Exception e) {
76 e.printStackTrace();
77 }
78 return lstZfpz;
79 }
80

2:使用JS 的逻辑处理

  1             var rows=[];  2
3 rows = mainGrid.getSelections();
5 if(rows.length>0){
6 debugger;
7 var balance_type="";
8
12 var rowsLength=rows.length;
13 var intFalg=30;//in 里面包含值的阀值
14 var ids=[];//id拼接存放的合集
15 var str_id="";
16 for (var i=0;i<rowsLength;i++){
17 var row =rows[i];
18 if(i%intFalg == 0 && i != 0 ){
19 ids.push(str_id);
20 str_id="";
21 }
22 if(i%intFalg == 0 ){
23 str_id = ""+row.id;
24 }else{
25 str_id = str_id+","+row.id;
26 }
27 if(i+1==rowsLength && ( rowsLength !=1 &&i%rowsLength != 0)){
28 ids.push(str_id);
29 } else if(i+1==rowsLength && rowsLength ==1 && i%intFalg == 0 ){
30 ids.push(str_id);
31 }
32 }
33 }
34

最新文章

  1. windows下安装Composer
  2. JS-为金额添加千分位逗号分割符
  3. Redis 发布订阅
  4. Android课程---Activity的跳转与传值(转自网上)
  5. iBatis.net入门指南
  6. redhat centos yum源的安装
  7. 让你的WPF程序使用多线程——BackgroundWorker
  8. EntityFramework之创建数据库及基本操作(一)
  9. Linq查询Count、Sum、Min、Max、Average
  10. List转xml
  11. 32位和64位adb下载及安装
  12. 能让汇编转到C51的初学者有更清晰的认识的一篇文章
  13. Qt Creator 代码自动补全设置
  14. Delphi中unicode转汉字函数(转)
  15. IIS Service Unavailable HTTP Error 503. The service is unavailable.
  16. shell中脚本与函数的使用策略
  17. 成功清除 windows2008 内部版本7601 字眼
  18. Linux内核编译指定输出目录
  19. 利用shell找出15分钟内修改的文件
  20. csdn 音乐 怎么拦截 提交后的程序 csdn 栏目 音乐 csdn 添加 音乐

热门文章

  1. Ubuntu中拷贝文件的操作
  2. 转载-HashMap1.8源码分析
  3. eslint 关于CRLF或者LF报错
  4. JQuery-change/select/submit
  5. CSS公共清除浏览器默认样式
  6. 【数据表格】datatable+SpringMVC+Spring Data JPA
  7. L - LCM Walk HDU - 5584 (数论)
  8. Django学习手册 - ORM sqlit基础数据库操作
  9. centos 秘钥登陆配置
  10. python目标定位(借鉴csdn上大神)