Caused by: java.sql.SQLException: ORA-01795: 列表中的最大表达式数为 1000解决方案

这个原因在于Oracle语法限制,in内数量必须小于1000,故采取满1000分割用OR连接,下面是解决方案:

	/**
	  * Example: List sqhlist=[''aa''"bb""cc""dd""ee""ff""gg"'] ;
	  * Test.getSqlStrByList(sqhList,3,"SHENQINGH")= "SHENQING IN
	  * ('aa','bb','cc') OR SHENQINGH IN ('dd','ee','ff') OR SHENQINGH IN ('g
	  *
	  * 把超过1000的in条件集合拆分成数量splitNum的多组sql的in 集合。
	  *
	  * @param sqhList
	  *            in条件的List
	  * @param splitNum
	  *            拆分的间隔数目,例如: 1000
	  * @param columnName
	  *            SQL中引用的字段名例如: Z.SHENQINGH
	  * @return
	  **/
	private static String getSqlStrByList(List sqhList, int splitNum,
			String columnName) {
		if (splitNum > 1000) // 因为数据库的列表sql限制,不能超过1000.
			return null;
		StringBuffer ids = new StringBuffer("");
		if (sqhList != null) {
			ids.append(" ").append(columnName).append(" IN ( ");
			for (int i = 0; i < sqhList.size(); i++) {
				ids.append("'").append(sqhList.get(i) + "'");
				if ((i + 1) % splitNum == 0 && (i + 1) < sqhList.size()) {
					ids.deleteCharAt(ids.length() - 1);
					ids.append(" ) OR ").append(columnName).append(" IN (");
				}
			}
			ids.deleteCharAt(ids.length() - 1);
			ids.append(" )");
		}
		return ids.toString();
	}

	public static void main(String[] args) {
		List list = new ArrayList();
		int id = 2;
		for(int i=0;i<1020;i++){
			list.add("'"+id+"'");
		}
		String ss = getSqlStrByList(list, 1000,"test");
		System.out.println(ss);
	}
时间: 2024-11-12 03:14:48

Caused by: java.sql.SQLException: ORA-01795: 列表中的最大表达式数为 1000解决方案的相关文章

Sql语句报ORA-01795: 列表中的最大表达式数为 1000

错误信息:java.sql.SQLException: ORA-01795: 列表中的最大表达式数为 1000,错误信息如下: serviceid是:work -------------other WorkCmd-------------------------hz2 <2017-6-13 下午06时23分06秒 CST> <Warning> <Socket> <BEA-000449> <Closing socket as no data read f

java jdbc oracle ORA-01795: 列表中的最大表达式数为 1000

在操作SQL中存在In的数量如果超过1000条会提示   ORA-01795: 列表中的最大表达式数为 1000 归纳有几种方式出现的: 第一种是:我在上一个 [jdbc 同时执行 查询和删除操]作中提到 在一个事务中在了in操作超出了 1000条,修改代码如下: Connection conn = null;        try {            // 创建连接实例            conn = JdbcUtility.GetFactory().CreateConn();   

IN 查询时出现ORA-01795:列表中的最大表达式数为1000解决方法

问题描述: SQL进行IN查询时出现:java.sql.SQLException: ORA-01795: 列表中的最大表达式数为 1000 解决办法: 问题原因是:SQL进行IN查询时,IN中的数据量不能超过1000条. 例如:select * from student where id in ('S1','S2'...........) 如果in后面数据量过多的话就会报错. 解决方法是:用 or关键字 如:select * from student where id in('S1','S2',

ORA-01795: 列表中的最大表达式数为 1000

系统报出一SQL异常,内容如下: java.sql.SQLException: ORA-01795: maximum number of expressions in a list is 1000 找出抛异常时执行的SQL语句,貌不惊人啊,很平常一SQL语句,内容类似:SELECT * FROM DUAL T WHERE T.DUMMY IN ('1', '2', '3', ...),只是IN后括号里的主键值多了些,其它没啥特别的. 看ORA-01795中给出的内容是SQL语句的 express

Caused by: java.sql.SQLException: Operand should contain 1 column(s)

1.错误描述 [ERROR:]2015-05-05 15:48:55,847 [异常拦截] org.hibernate.exception.DataException: error executing work at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:135) at org.hibernate.exception.internal.

Caused by: java.sql.SQLException: Parameter index out of range (1 &gt; number of parameters, which is 0

1.错误描述 org.hibernate.exception.GenericJDBCException: error executing work at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(Sql

解决sqoop导入报错:Caused by: java.sql.SQLException: Protocol violation

报错信息: 2017-06-15 15:02:15,374 INFO [main] org.apache.hadoop.mapred.MapTask: Ignoring exception during close for [email protected]0 java.io.IOException: java.sql.SQLException: Protocol violation at org.apache.sqoop.mapreduce.db.DBRecordReader.close(DB

Caused by: java.sql.SQLException: Couldn&#39;t perform the operation commit

1.错误描述 Caused by: java.sql.SQLException: Couldn't perform the operation commit: You can't perform any operations on this connection. It has been automatically closed by Proxool for some reason (see logs). at org.logicalcobwebs.proxool.WrappedConnecti

Caused by: java.sql.SQLException: Field &#39;id&#39; doesn&#39;t have a default value

1.错误描述 org.hibernate.exception.GenericJDBCException: error executing work at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(Sql