Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8306227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:17:16+00:00 2026-06-08T18:17:16+00:00

I’m faced with the task of having to look in a database with millions

  • 0

I’m faced with the task of having to look in a database with millions of records, which codes of a set of about 1500 have a corresponding record, which ones of those exist in the db. For example i have 1500 IDs in a csv file. I want to know which ones of those IDs exist in the database, and are therefore correct, and which ones don’t.

Is there a better way of doing this without “… WHERE id IN (1, 2, 3, ..., 1500);” ?
The DB/language in question is ORACLE PL/SQL.

Thanks in advance for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:17:17+00:00Added an answer on June 8, 2026 at 6:17 pm

    Build an external table on your CSV file. These are highly neat things which allow us to query the contents of an OS file in SQL. Find out more.

    Then it’s a simple matter of issuing a query:

    select csv.id
           , case ( when tgt.id is null then 'invalid' else 'valid') end as valid_id
    from your_external_tab csv
           left join target_table tgt on (csv.id = tgt.id)
    

    “CSV table is hardly ideal from a performance point of view”

    Performance is a matter of context. In this case it depends on how often the data in the CSV changes and how often we need to query it. If the file is produced once a day and we only need to check the values after it has been delivered then an external table is the most efficient solution. But if this data set is a permanent repository which needs to be queried often then the overhead of writing to a heap table is obviously justified.

    To me, a CSV file consisting of a bunch IDs and nothing else sounds like transient data and so
    fits the use case for external tables. But the OP may have additional requirements which they haven’t mentioned.


    Here is an alternative approach which doesn’t require creating any permanent database objects. Consequently it is less elegant, and probably will perform worse.

    It reads the CSV file labouriously using UTL_FILE and populates a collection based on SYSTEM.NUMBER_TBL_TYPE, a pre-defined collection (nested table of NUMBER) which should be available in your Oracle database.

    declare
        ids system.number_tbl_type;
        fh utl_file.file_handle;
        idx pls_integer := 0;
        n pls_integer;
     begin
        fh := utl_file.fopen('your_data_directory', 'your_data.csv', 'r');
        begin
            utl_file.get_line(fh, n);
            loop  
                idx := idx + 1;
                ids.extend();
                ids(idx) := n;
                utl_file.get_line(fh, n);
            end loop;
       exception
          when no_data_found then
              if utl_file.is_open(fh) then
                 utl_file.fclose(fh);
              end if;
         when others then
              raise;
      end;
      for id_recs in  in  ( select csv.column_value 
                  , case ( when tgt.id is null then 'invalid' else 'valid') end as valid_id
                    from (select * from table(ids)) csv
                left join target_table tgt on (csv.column_value = tgt.id)
      ) loop
      dbms_output.put_line '(ID '||id_recs.column_value || ' is '||id_recs.valid_id);
      end loop;
    end;
    

    Note: I have not tested this code. The principle is sound but the details may need debugging 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
I have a view passing on information from a database: def serve_article(request, id): served_article
I have two tables with like below codes: Table: Accounts id | username |
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.