In the project I'm working on, there are many IN queries like:
SELECT something, anotherthing FROM atable WHERE something IN (value1, value2, value3)
This is an example request with 3 parameters in the IN part, but the same request can be executed with 1 or 2 or 5 or 10 or ... parameters. The problem is that each request has a different execution plan in the database, which makes it slow.
I would like to ask a query like this:
SELECT something, anotherthing FROM atable WHERE something IN (@value1, @value2, @value3)
or that:
SELECT something, anotherthing FROM atable WHERE something IN (@values)
I executed the first request with some helper function, but I still have a different execution plan for the number of parameters. This can be solved using the second.
What is the best way to pass an array as a database parameter? I use Oracle and SQL Server, solutions for both of them are welcome.
Jochen
source share