0

I have a file SRQ which is having 10000 SRQ_ID which are unique. I have one table(TABLE1) which is having 2 columns namely SRQ_ID,WORK_ID . I needs to write a query which will search the table(TABLE1) for all the SRQ_ID's in the file SRQ and will display the output with corresponding WORK_ID.

I tried the below code. But IN clause is only applicable for 1000 records. How to run the same if I have 100k records?

select WO_ID 
from TABLE1 
where SRQ_ID in ('B6512DF0','5838FABC','EC5D804C','074DD65C')
user2642751
  • 43
  • 1
  • 9
  • 1
    What SQL database are you using? – StingyJack Dec 06 '13 at 12:50
  • @StingyJack seems like it's PostgreSQL – dlock Dec 06 '13 at 12:54
  • @deadlock - Is the 1K limit a postgres thing? – StingyJack Dec 06 '13 at 13:04
  • @deadlock: I don't see any indication that this is for Postgres. And judging by the "*applicable for 1000 records*" I actually think it's Oracle, because Oracle only allows for 1000 literal values in the `IN` operator –  Dec 06 '13 at 13:05
  • Without RDBMS it is unclear what you'Re asking. With RDBMS it is duplicate. Just use a search engine to find out answer and delete this question. This is duplicated 100s of times. – usr Dec 06 '13 at 13:07
  • @StingyJack it's originally an Oracle issue. I thought it's a PostgreSQL too. But it seems not! – dlock Dec 06 '13 at 13:17
  • i got the answer using union all approach.. it worked fine for me..thanks a lot to all .. – user2642751 Dec 06 '13 at 13:35

3 Answers3

0

Is there a reason you can't just do a join between the tables using SRQ_ID?

select wo_id from table1 join srq using srq_id

This will give you the work id for all rows that have a srq_id value in the srq table.

Mark Wagoner
  • 1,729
  • 1
  • 13
  • 20
0

If the file s on the database server then you could access it as an external table, and join the two. Otherwise, I'd suggest bulk loading the codes into a global temporary table and performing the join against that.

David Aldridge
  • 51,479
  • 8
  • 68
  • 96
0

In case you don't like to create a temporary table, you can use a nested table:

CREATE OR REPLACE TYPE VARCHAR_TABLE_TYPE AS TABLE OF VARCHAR2(20);

select WO_ID 
from TABLE1 
where SRQ_ID MEMBER OF VARCHAR_TABLE_TYPE('B6512DF0','5838FABC','EC5D804C','074DD65C');

But I don't know the limit for initializing a nested table. Oracle documentation says: "Because a nested table does not have a declared size, you can put as many elements in the constructor as necessary."

Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110