博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Oracle ORA-01460报错解决方法
阅读量:2040 次
发布时间:2019-04-28

本文共 3389 字,大约阅读时间需要 11 分钟。

最近遇到一个oracle错误,之前并没有遇到过,并不是select in超过1000个导致的,通过网上资料说是oracle版本导致,也有的说是oracle SQL过长导致。

然后通过自己实践应该说是oracle SQL过长导致,看了一下SQL并不是很长,主要还是select in,因为主键换成uuid之后,来几百个uuid的数据,select in就导致SQL过长报错,我觉得网上所说的换oracle版本,也有可能是oracle版本对SQL过长支持不同。不过我还是通过改写业务SQL解决问题的。项目中也不可能随便就换oracle版本。

原来的代码,主要是select in 然后itemCode就是用;分隔的一大串的主键字符串,然后又换成uuid的了,所以导致sql过长

/**	 * 获取信息模板	 * @return	 */	private List
getSettingTemplate(String itemCode) throws SQLException { PreparedStatement pst = null; StringBuffer sb = new StringBuffer(); sb.append("select a.itemCode, "); sb.append("a.type, "); sb.append("b.warn_days, "); sb.append("c.proj_name, "); sb.append("c.cust_name, "); sb.append("a.is_send "); sb.append("from t_item_setting a "); sb.append("left join t_itm_define b on b.itemCode= a.itemCode "); sb.append("b.itemCode where a.is_send in (1) and a.itemCode in (?) "); pst = this.connection.prepareStatement(sb.toString()); pst.setString(1, itemCode); ResultSet rs = pst.executeQuery(); List
list = new ArrayList
(); while(rs.next()){ ItemSettingVo vo = new ItemSettingVo(); vo.setItemCode(rs.getString("itemCode")); vo.setType(rs.getLong("type")); vo.setSmsTemplet(rs.getString("sms_templet")); vo.setWarnDays(rs.getLong("warn_days")); vo.setIsSend(rs.getLong("is_send")); list.add(vo); } rs.close(); pst.close(); return list; }

解决方法:用分组遍历再拼装为一个List的方法,这样就可以避免select in,然后in里面又是一大堆uuid的数据,然后就导致sql执行过长报错了

/**	 * 获取信息模板	 * fixed #ORA-01460: 转换请求无法实施或不合理	 * ps:主键换成uuid之后,原来的方法会出现ORA-01460出错,sql太长导致	 * @param itemCode	 * @return	 * @throws Exception	 */	public List
getItemSettingVos(String itemCode)throws Exception{ List
templateList = new ArrayList
(); StringBuffer itmStr = new StringBuffer(); //XXX fixed Exception#ORA-01460: 转换请求无法实施或不合理 modify on 20190109 //暂时用分组遍历再拼装为一个List的方法,原来的方法放在getSettingTemplate if(StringUtils.isNotBlank(itemCode)){ //itemCode = itemCode.replace("(", "").replace(")", ""); String[] itemCodeArr = StringUtils.split(itemCode,","); int len = itemCodeArr.length; if (len < 100) {//没超过100个事项编码的情况,按照原来的方法 templateList = this.getSettingTemplate(itemCode); } else {//超过100个事项编码的情况,分组遍历,然后再拼装list,避免Exception#ORA-01460: 转换请求无法实施或不合理 List
> itms =CollectionUtils.splitCollection(Arrays.asList(itemCodeArr), 100); for (Collection
colle: itms) { for (String str : colle) { itmStr.append("'").append(str).append("'").append(","); } itemCode = itmStr.toString().substring(0, itmStr.toString().length()-1); templateList.addAll(this.getSmsSettingTemplate(itemCode)); itmStr.delete(0, itmStr.length()); } System.out.println("get apprTemplateList:{}"+templateList.size()); } } return templateList; }

集合拆分工具类,工具类复制公司同事写的代码

import java.util.ArrayList;import java.util.Collection;import java.util.List;public class CollectionUtils {	public static List
> splitCollection(Collection
values , int size) { List
> result = new ArrayList
>(); if(values.size() <= size ){ result.add(values); }else{ int count =0; Collection
subCollection= null; for(String s:c){ if(subCollection == null){ subColletion = new ArrayList
(); result.add(subColletion); } subCollection.add(s); count++; if(count == size){ count =0; subCollectiion = null; } } } }}

转载地址:http://mycof.baihongyu.com/

你可能感兴趣的文章
Leetcode C++《热题 Hot 100-22》2.两数相加
查看>>
Leetcode C++《热题 Hot 100-23》3.无重复字符的最长子串
查看>>
Leetcode C++《热题 Hot 100-24》5.最长回文子串
查看>>
Leetcode C++《热题 Hot 100-25》11.盛最多水的容器
查看>>
Leetcode C++《热题 Hot 100-26》15.三数之和
查看>>
Leetcode C++《热题 Hot 100-27》17.电话号码的字母组合
查看>>
Leetcode C++《热题 Hot 100-28》19.删除链表的倒数第N个节点
查看>>
Leetcode C++《热题 Hot 100-29》22.括号生成
查看>>
Leetcode C++《热题 Hot 100-30》31.下一个排列
查看>>
Leetcode C++《热题 Hot 100-40》64.最小路径和
查看>>
Leetcode C++《热题 Hot 100-41》75.颜色分类
查看>>
Leetcode C++《热题 Hot 100-42》78.子集
查看>>
Leetcode C++《热题 Hot 100-43》94.二叉树的中序遍历
查看>>
Leetcode C++ 《第175场周赛-1 》5332.检查整数及其两倍数是否存在
查看>>
Leetcode C++ 《第175场周赛-2 》5333.制造字母异位词的最小步骤数
查看>>
Leetcode C++ 《第175场周赛-3》1348. 推文计数
查看>>
Leetcode C++《热题 Hot 100-44》102.二叉树的层次遍历
查看>>
Leetcode C++《热题 Hot 100-45》338.比特位计数
查看>>
读书摘要系列之《kubernetes权威指南·第四版》第一章:kubernetes入门
查看>>
Leetcode C++《热题 Hot 100-46》739.每日温度
查看>>