It appears that there is a limit of 1000 arguments in an Oracle SQL. I ran into this when generating queries such as….
select * from orders where user_id IN(large list of ids over 1000)
My workaround is to create a temporary table, insert the user ids into that first instead of issuing a query via JDBC that has a giant list of parameters in the IN.
Does anybody know of an easier workaround? Since we are using Hibernate I wonder if it automatically is able to do a similar workaround transparently.
An alternative approach would be to pass an array to the database and use a
TABLE()function in the IN clause. This will probably perform better than a temporary table. It will certainly be more efficient than running multiple queries. But you will need to monitor PGA memory usage if you have a large number of sessions doing this stuff. Also, I’m not sure how easy it will be to wire this into Hibernate.Note:
TABLE()functions operate in the SQL engine, so they need us to declare a SQL type.The following sample populates an array with a couple of thousand random tags. It then uses the array in the IN clause of a query.