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

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

     

    [原著]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 
      








  • 相关阅读:
    Discuz X 2.5 点点(伪静态)
    jq 、xml 省市级联动
    php memcache 初级使用(2)
    关于windows虚拟内存管理的页目录自映射
    SharePoint 2010 网络上的开发经验和资源
    SharePoint 2010 Reporting Services 报表服务器正在内置 NT AUTHORITY\SYSTEM 账户下运行 解决方法
    SharePoint 2010 Reporting Services 报表服务器无法解密用于访问报表服务器数据库中的敏感数据或加密数据的对称密钥 解决方法
    Active Directory Rights Management Services (AD RMS)无法检索证书层次结构。 解决方法
    SharePoint 2010 Reporting Services 报表服务器实例没有正确配置 解决方法
    SharePoint 2010 页面引用 Reporting Services 展现 List 报表
  • 原文地址:https://www.cnblogs.com/ios9/p/8580360.html
Copyright © 2011-2022 走看看