I need to devise a subquery to select the rows having matching values in a column.
Example
Select *
from person
where first_name in ('Java','SQL','Oracle');
However this list inside the parenthesis can be big, upto 30,000 values. I will be reading the values from a file and will be passing it inside this the parenthesis. However I thought there might be a limitation to the number of values that I can provide inside the parenthesis. Is there an optimal solution to address this scenario without creating and loading a new table with data?
EDIT: Thanks for your responses. Is the below query an option to be considered –
Select *
from person
where first_name like 'Java'
or first_name like 'SQL'
or first_name like 'Oracle';
Thanks.
I agree with Jonathan, concetanating 30000 values is not the way to go here, and his solution is a good way. But here is another idea, Oracle has a nice feature called External Tables.
With External Tables, you can treat a file as if it is a table. If your file is well structured (like CSV) you can easily use this feature.
Google “Oracle External Tables” and you’ll find a lot of information and examples, but for starters read this:
Basically, you’ll need a directory object to tell Oracle where your file is located, then you will create the External Table, perhaps something like below:
Using this table in your query:
EDIT: See APC’s comment, he has a good point.