views:

55

answers:

3

I have a table my_table with column my_column and a large list my_list of LONGs. I'd like to find all values that present in the my_list but not present in the my_table.my_column. How can I do that with SQL without repeating huge list of LONGs twice? Please shed some light as I'm Oracle beginner. Thank you.

EDIT:

my_list is just a short form of comma-separated values (1, 2, 3, 4), it's not a variable, just a way to call.

A: 

maybe

select * from my_table where my_column not in (my_list)

where my_list - comma-separated values list. and how large is your list?

heximal
Sorry, I need to find those in my_list but NOT in my_column. You need to read more carefully.
Viet
And please never select *
Viet
A bit harsh, Viet. And unless heximal has edited it since you commented, it SAYS "NOT in". Also, berating him/her for using "select *" in a simple example is a bit over the top.
Tony Andrews
thanks, Tony) i meant exaclty what you said. but author is also right and i should be more careful when readning questions. and i'm going to be. promise)
heximal
A: 
SELECT * FROM my_list
EXCEPT
SELECT * FROM my_table
Benoit
In Oracle it is "MINUS" not "EXCEPT", otherwise OK (assuming my_list is a table).
Tony Andrews
my_list is not a table, it has format of (1,2,3,4,5,...,100)
Viet
+2  A: 

If your list is constant, it's probably a good idea to store it in a reference table and to use a join as suggested to filter the records.

Otherwise you might reach 2 limits: the max length for a SQL statement and the maximum number of items that Oracle allows in a list. The latter can be solved by splitting your big list into smaller lists (my_column no in (...) and my_column not in (...)).

vc 74
+1 sounds good. Thanks. Say I have 50 LONGs only, so how we can work with the list without using temporary table?
Viet
If your list is constant, you could create a pipelined function returning its values accessible from your SQL queries as if it was stored in a table
vc 74