Java NamedParameterJdbcTemplate不';当第100条或第1000条中规定的值超过100或1000时,不工作
我正在使用NamedParameterJdbcTemplate运行我的查询。查询如下:Java NamedParameterJdbcTemplate不';当第100条或第1000条中规定的值超过100或1000时,不工作,java,spring,Java,Spring,我正在使用NamedParameterJdbcTemplate运行我的查询。查询如下: SELECT id, desc FROM tableA WHERE id IN (:custIds); 现在,我调用一个web服务,它返回一个ID列表。因此,我使用NamedParameterJdbcTemplate将ID列表映射到“custIds”。然而,当ID列表超过1000时,我遇到了一个问题。我已经读到DB将无法处理包含100或1000个以上的数据 由于我只能收到ID列表,除了NamedParame
SELECT id, desc FROM tableA WHERE id IN (:custIds);
现在,我调用一个web服务,它返回一个ID列表。因此,我使用NamedParameterJdbcTemplate将ID列表映射到“custIds”。然而,当ID列表超过1000时,我遇到了一个问题。我已经读到DB将无法处理包含100或1000个以上的数据
由于我只能收到ID列表,除了NamedParameterJdbcTemplate之外,您能建议最好使用什么吗?在
子句中,您不能使用超过1000个条目。有以下几种解决方案:
- 使用
内部查询
解决此问题。您可以创建一个临时表,并在in
子句中使用它
示例查询:
select id,desc from table_name where id in (select id from temp_table)
select id,desc from table_name
where
id in (1,2,3,...1000)
or
id in (1001,1002,1003,...2000)
or
id in (2001,2002,...)
select id,desc from table_name where id in (1,2,3,4,...,1000)
union all
select id,desc from table_name where id in (1001,1002,...2000)
union all
select id,desc from table_name where id in (2001,2002,...)
- 在
子句中使用多个由或子句分隔的,将其拆分为1000个条目
示例查询:
select id,desc from table_name where id in (select id from temp_table)
select id,desc from table_name
where
id in (1,2,3,...1000)
or
id in (1001,1002,1003,...2000)
or
id in (2001,2002,...)
select id,desc from table_name where id in (1,2,3,4,...,1000)
union all
select id,desc from table_name where id in (1001,1002,...2000)
union all
select id,desc from table_name where id in (2001,2002,...)
- 或者使用
union all
代替上述或
子句,在
子句中的中查询1000个条目
示例查询:
select id,desc from table_name where id in (select id from temp_table)
select id,desc from table_name
where
id in (1,2,3,...1000)
or
id in (1001,1002,1003,...2000)
or
id in (2001,2002,...)
select id,desc from table_name where id in (1,2,3,4,...,1000)
union all
select id,desc from table_name where id in (1001,1002,...2000)
union all
select id,desc from table_name where id in (2001,2002,...)
请参见您在
子句中的中不能使用超过1000个条目。有以下几种解决方案:
- 使用
内部查询
解决此问题。您可以创建一个临时表,并在in
子句中使用它
示例查询:
select id,desc from table_name where id in (select id from temp_table)
select id,desc from table_name
where
id in (1,2,3,...1000)
or
id in (1001,1002,1003,...2000)
or
id in (2001,2002,...)
select id,desc from table_name where id in (1,2,3,4,...,1000)
union all
select id,desc from table_name where id in (1001,1002,...2000)
union all
select id,desc from table_name where id in (2001,2002,...)
- 在
子句中使用多个由或子句分隔的,将其拆分为1000个条目
示例查询:
select id,desc from table_name where id in (select id from temp_table)
select id,desc from table_name
where
id in (1,2,3,...1000)
or
id in (1001,1002,1003,...2000)
or
id in (2001,2002,...)
select id,desc from table_name where id in (1,2,3,4,...,1000)
union all
select id,desc from table_name where id in (1001,1002,...2000)
union all
select id,desc from table_name where id in (2001,2002,...)
- 或者使用
union all
代替上述或
子句,在
子句中的中查询1000个条目
示例查询:
select id,desc from table_name where id in (select id from temp_table)
select id,desc from table_name
where
id in (1,2,3,...1000)
or
id in (1001,1002,1003,...2000)
or
id in (2001,2002,...)
select id,desc from table_name where id in (1,2,3,4,...,1000)
union all
select id,desc from table_name where id in (1001,1002,...2000)
union all
select id,desc from table_name where id in (2001,2002,...)
请参见如何创建一个带有ID的临时表并在查询中使用它?好的,我会试试。感谢我的经验限制…IN来自数据库,而不是SpringJDBC。看看你用的是什么数据库?是的,我也同意对数据库的限制。我正在使用Oracle。用ID创建一个临时表并在查询中使用它怎么样?好的,我试试看。感谢我的经验限制…IN来自数据库,而不是SpringJDBC。看看你用的是什么数据库?是的,我也同意对数据库的限制。我在用甲骨文。