Is it possible in a single SQL statement to do the following:
Use a subset of telephone numbers in a prompt, for example 8001231000-8001239999
. Then query my database that has phone numbers in it, and return which phone numbers in the original subset are NOT in my database? My db is Oracle 10g.
Basically instead of bringing back which phone numbers ARE between 8001231000-8001239999
, I want to know which phone numbers between 8001231000-8001239999
are NOT in my database.
You are looking for the "NOT IN" Operator with a subquery matching those telephone numbers.
Assuming that the phone number is a NUMBER, you can generate the list of all phone numbers in a particular range
You can then join this list of all the phone numbers in the range to your actual table of phone numbers. Something like
Something like this:
Create a pseudo-list of all possible numbers and exclude existing numbers from it.
If your phone numbers are character:
or if they are numeric:
I can't think of a way to do it with a single select, but you can do it with a single transaction. Specifically:
Edit: Bill Karwin's answer is better. Same concept with the temp table, but then a single select to pull out the values that don't exist.
I would load a temporary table with all 10000 phone numbers in the range you want to check, and do an exclusion join: