views:

182

answers:

5

I have an oracle database that I have read-only access (with no permission to create temporary tables). I have a pick list (in Excel) of 28000 IDs corresponding to 28000 rows in a table which has millions of records. How do I write a query to return the 28000 rows?

I tried creating a table in access and performing a join through ODBC but Access freezes/takes an incredible long time. Would I have to create a query with 28,000 items in an IN statement?

Is there anything in PL/SQL that would make it easier?

Thank you for your time and help.

-JC

A: 

The max number of variables for an IN (.., .. ,,) type query is 1000 in Oracle 10g.

Gandalf
Good to know, thanks!
JC
+3  A: 

What makes your 28,000 rows special?

Is there another field in the records you can use to restrict you query in a WHERE clause (or at least narrow down the millions of rows a bit)? Perhaps the ID's you're interested in fall within a certain range?

Graham Miller
The IDs are actually a combination of a phone number and a time. That's pretty much what makes the row unique.
JC
I believe Graham is asking what differentiates your 28,000 rows from the millions of rows in the table that you're not interested in. Can you devise a query that finds those 28,000 rows that doesn't involve 28 separate IN lists of 1000 literals a piece?
Justin Cave
+1, hits the nail on the head. If you can't come up with an answer to this, you're in for one of the painful solutions that others have given.
DCookie
They do fall within a certain date range but so do hundreds of thousands of other records. I'm still a bit confused at how this will help me other than perhaps making the query a bit faster. Wouldn't I still have to write multiple IN lists?
JC
A: 

Try creating an index on the table you created in Access.

Mark Roddy
A: 

That's a painful condition to be in. One workaround is to create a view that contains all of the ids, then join to it.

The example below is Oracle.

WITH
ids AS
(
    SELECT 314 ID FROM DUAL UNION ALL
    SELECT 159 ID FROM DUAL UNION ALL
    SELECT 265 ID FROM DUAL
)
SELECT VALUE1, VALUE2
FROM SOME_TABLE, ids
WHERE SOME_TABLE.ID = ids.ID

This basically embeds all 28000 ids, in the with clause, allowing you to do the join, without actually creating a table.

Ugly, but it should work.

EvilTeach
A: 

The best way to do it is described here: http://stackoverflow.com/questions/400255/how-to-put-more-than-1000-values-into-an-oracle-in-clause/400295#400295

Theo
Hard to do when you don't have write access to the database.
EvilTeach
Why? Nothing is written in the db!
Theo
Unfortunately, I do not have access to create temporary tables :(
JC
@JC, The example of the link above doesn't require any temporary tables. Use the '...from table(...' construction!! It is very speedy!
Theo