0

Hope all is well. I have a table with about 491,000 unique records in a SQL server database. I need to run these records against another table in Oracle database. The problem I have in Oracle is it can on filter 1000 records at a time. Here is the query and its error:

SELECT *
FROM TABLE1
WHERE ID IN(A LIST OF 1001 RECORDS)

[Error] Script lines: 1-4 -------------------------- ORA-01795: maximum number of expressions in a list is 1000 Script line 3, statement line 3, column 11017

I can use the following query to run for couple thousand records but not sure how to do it with 491000 records.

SELECT ID
FROM TABLE2
WHERE (  ID IN(LIST OF 1000 RECORDS)
OR ID IN(LIST OF ANOTHER 1000 RECORDS)
OR ID IN(LIST OF ANOTHER 1000 RECORDS)
OR ID IN(LIST OF ANOTHER 1000 RECORDS))

Could anyone helpe me this this problem?

Many thanks

Forget to mention, I do not have privillage to create tables in Oracle database.

4
  • 1
    is there no rule to the ID's? like between 1 and 491000? Commented Mar 16, 2012 at 17:54
  • could you select all the rows from oracle and filter them in your application? Commented Mar 16, 2012 at 18:00
  • @April, I am running the query it now. it takes about two hours to pull those records Ahww, ahww Commented Mar 16, 2012 at 18:04
  • well, that's what count(*) and where rownum < 1000 are for while testing something ;)) Commented Mar 16, 2012 at 18:17

2 Answers 2

1

EDIT:

Since you can't create tables in your Oracle database, have you considered using a Linked Server to join straight from your SQL Server table to your Oracle table?

How to set up and troubleshoot a linked server to an Oracle database in SQL Server

You could create the linked server using code similar to:

-- Adding linked server (from SQL Server Books Online):
/* sp_addlinkedserver [@server =] 'server' 
    [, [@srvproduct =] 'product_name']
    [, [@provider =] 'provider_name'] 
    [, [@datasrc =] 'data_source'] 
    [, [@location =] 'location'] [, [@provstr =] 'provider_string'] 
    [, [@catalog =] 'catalog']
*/ 

EXEC sp_addlinkedserver   'Ora817Link',  'Oracle',  'MSDAORA',  'oracle817'

-- Adding linked server login:
/* sp_addlinkedsrvlogin [@rmtsrvname =] 'rmtsrvname'
    [,[@useself =] 'useself']
    [,[@locallogin =] 'locallogin']
    [,[@rmtuser =] 'rmtuser']
    [,[@rmtpassword =] 'rmtpassword']
*/ 

EXEC sp_addlinkedsrvlogin 'Ora817Link', 'FALSE',NULL, 'scott', 'tiger'

Which would then allow you to perform a simple join between the two tables that reside on two different servers:

SELECT ot.ID
FROM 
    YourOracleServer...OracleTable ot
    JOIN SQLServerTable st ON ot.ID = st.ID
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Mike, I forget to mention, I dont have privilage to create tables in Oracle database.
Thanks again Mike, I appreciate your quick help
These linked server codes are boyond my experience... Still trying to get the job done though.
0

As @Aprillion mentionned, normally there would be a pattern for which ID's are relevant to fetch.

Suppose you have ID's for where the name is 'Bob', do this:

SELECT * 
FROM TABLE1
WHERE name = 'Bob'

If name is in another table, use a subquery:

SELECT *
FROM TABLE1
WHERE ID IN (SELECT ID FROM TABLE2 WHERE name = 'Bob');

Or a join:

SELECT TABLE1.*
FROM TABLE1 INNER JOIN TABLE2 ON TABLE1.ID=TABLE2.ID
WHERE name = 'Bob';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.