oracle - How to pass a very long list in jdbcTemplate spring-boot
问题描述
I am using oracle datasource which does not allow more than 1000 records in a query.
My idList contain 10K or more which would be dynamic
My unit test is
@Test
public void testLongListParameter(){
String QUERY = "select value from sample_table where id in (:ids)";
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate.getDataSource());
Map idMap = Collections.singletonMap("ids", idList);
namedParameterJdbcTemplate.query(QUERY, idMap, new CustomRowMapper());
}
when I run this I get ORA-01795: maximum number of expressions in a list is 1000
so the problem is I have more argument than limit of oracle. to resolve this do I have to write my custom query generator or does spring already have something similar.
解决方案
一切最终都必须使用 JDBC API……而且列表的限制100
。SELECT
任何比这更大的东西都不能保证得到数据库的支持。您已经达到了 Oracle 的极限,但它也可能是其他一些供应商。
在这方面你真的无能为力。
在另一个领域,破解解决方案,您可以:
- 将
IN
子句分成几个OR
'ed 块(块大小由您决定,您可以使用100
or1000
因为您知道这是您达到的限制) IN
将数据集插入到临时表中,然后在子句中使用子查询
推荐阅读
- powershell - 框架不同部分的自动化
- mysql - 限制用户的服务器资源时出错
- mongodb - MongoDB Compass 使用 ssl 立即断开连接,但从命令行可以正常工作
- php - 我正在使用 zklib 库生物识别设备来获取学生的出勤记录,但它向我显示空白页
- git - Azure DevOps 中新创建的 git 分支未显示在 Visual Studio 2017 中
- python - “资源耗尽:分配张量时的 OOM”在 GPT 2 模型的重新训练期间:
- python - 如何从键列表和列表值快速构建 python 字典?
- python - 在 Python 3.6+ 中,将浮点 9.9 打印为字符串 09.90 和将 10 打印为 10.00 的 f 字符串是什么?
- php - 搜索中的 Laratable 模棱两可的列
- php - 在 PHP 中用指向同一域的链接替换纯文本