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