We have a lot of data in database and sometimes we need to call sql statements with more than 1000 items in IN clause. I know that those sql statements should be refactored and IN clause shouldn't have that much items but sometimes it's not that easy to keep an eye on each sql query. So I have a few questions.

我们在数据库中有很多数据,有时我们需要在IN子句中调用超过1000个项目的sql语句。我知道那些sql语句应该被重构,IN子句不应该有那么多项,但有时候并不容易注意每个sql查询。所以我有几个问题。

  1. What are the possibilities to solve this problem? I found few:
    • refactor sql statements - not always that easy
    • 重构sql语句 - 并不总是那么容易
    • create temporary table for items so IN clause will look like this ... IN (SELECT id from temptable) - might be a good idea
    • 为项创建临时表,因此IN子句将如下所示... IN(来自temptable的SELECT id) - 可能是一个好主意
    • divide IN clause into few IN clauses like ... id IN (...) or id IN (...)
    • 将IN子句分成几个IN子句,如... id IN(...)或id IN(...)
  2. 有什么可能解决这个问题?我发现很少:重构sql语句 - 并不总是那么容易为项创建临时表,所以IN子句看起来像这样...... IN(来自temptable的SELECT id) - 可能是一个好主意将IN子句分成几个IN子句如... .ID IN(...)或id IN(...)
  3. Oracle db has limit for IN clause but I haven't found that limit for HSQLDB which we use for unit tests. Is it possible to set this limit through some configuration or some other way in HSQLDB?
  4. Oracle db对IN子句有限制,但我没有找到我们用于单元测试的HSQLDB限制。是否可以通过HSQLDB中的某些配置或其他方式设置此限制?
  5. Regarding temporary table for IN clause - how to create temporary table using HQL (we use Hibernate 4.2 in our application)? Is it possible?
  6. 关于IN子句的临时表 - 如何使用HQL创建临时表(我们在应用程序中使用Hibernate 4.2)?可能吗?
  7. Currently some IN clauses won't have more than 1000 items because we don't have that much data in db. But after application will be started on production (it is still in development process) there will be a lot of more data so we want to be ready for this.
  8. 目前,一些IN子句不会超过1000个项目,因为我们在db中没有那么多数据。但是在应用程序将开始生产(它仍在开发过程中)之后会有更多的数据,所以我们希望为此做好准备。

What are your experiences with this problem. How have you solved it?

您对此问题有什么经验?你是怎么解决的?

Details about our environment:

有关我们环境的详情:

  • Hibernate 4.2
  • Hibernate 4.2
  • HSQLDB 2.3.2
  • HSQLDB 2.3.2
  • ORACLE 11g
  • ORACLE 11g

2 个解决方案

#1


1

Re question 2, HSQLDB does not impose a limit on the number of items in the IN clause and no limit can be imposed.

问题2,HSQLDB不对IN子句中的项目数施加限制,也不能施加限制。

更多相关文章

  1. Mysql order by语句未使用索引的思考
  2. SQL语句练习(1)
  3. 存款日均额计算的SQL语句如何书写
  4. android应用如何在有需要时申请root权限?在程序中要调用哪些语句
  5. 错误:未使用的导入语句 - 导入android.widget.AdapterView.OnItem
  6. 我在Java中组织这些if语句时遇到了很多麻烦
  7. 准备语句SQL异常“无输入参数”
  8. java7 switch语句使用字符串
  9. Java日志框架——查看“完整的执行的SQL语句”

随机推荐

  1. XML创建可排序、分页的数据显示页面
  2. 详细介绍Xml数据解析的三种方式的示例代
  3. 教你如何快速通过XSL转换XML文件的详解
  4. 详细告诉你为何XML对Web服务很重要
  5. 关于XML数据库中几个容易混淆的概念详解
  6. 详细介绍xml中的空格之完全解说
  7. HTML中的XML数据岛记录编辑与添加代码实
  8. 利用XML开发留言板简单的实例代码解析
  9. xml入门:XML是什么,它可以做什么?
  10. 教你怎么样快速通过XSL转换XML文件