For example, you have a simple table with just one column.
ie.
CREATE TABLE movies (title VARCHAR2(255 BYTE))
set up with the following data:
INSERT INTO movies (title) VALUES ('Scream');
INSERT INTO movies (title) VALUES ('Blair Witch');
INSERT INTO movies (title) VALUES ('Friday the 13th');
INSERT INTO movies (title) VALUES ('Scary Movie');
INSERT INTO movies (title) VALUES ('Hide and Seek');
INSERT INTO movies (title) VALUES ('Alien vs Predator');
Is there a single query or PL/SQL that will do the following dynamically (ie without having to manually do a “UNION select ‘scream’ from dual…” for every value)?
Obviously this query is wrong but you get the idea:
Select * from movies
where title in (
'Scream',
'Scary Movie',
'Exorcist',
'Dracula',
'Saw',
'Hide and Seek'
)
Desired result being a record for every value in the “WHERE TITLE IN” clause where the record is not present in the table.
ie.
'Exorcist'
'Dracula'
'Saw'
If you’re using 10g or higher, you can build a function which converts a CSV string into a dynamic table. Check out the code for a string tokenizer in this other response.
You would use it like this:
Here is a slightly simpler implementation which doesn’t require any additional infrastructure:
This is similar to the Table Value Constructor, but it does only work for single column “tables”.