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

  • Home
  • SEARCH
  • 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 1014427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:15:09+00:00 2026-05-16T10:15:09+00:00

EDIT: changed the title to fit the code below. I’m trying to retrieve a

  • 0

EDIT: changed the title to fit the code below.

I’m trying to retrieve a list of acceptable values from an Oracle table, then performing a SELECT against another while comparing some fields against said list.

I was trying to do this with cursors (like below), but this fails.

DECLARE
    TYPE gcur IS REF CURSOR;
    TYPE list_record IS TABLE OF my_table.my_field%TYPE;
    c_GENERIC gcur;
    c_LIST list_record;
BEGIN
    OPEN c_GENERIC FOR
    SELECT my_field FROM my_table
    WHERE some_field = some_value;

    FETCH c_GENERIC BULK COLLECT INTO c_LIST;

    -- try to check against list
    SELECT * FROM some_other_table
    WHERE some_critical_field IN c_LIST;

END

Basically, what I’m trying to do is to cache the acceptable values list into a variable, because I will be checking against it repeatedly later.

How do you perform this in Oracle?

  • 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-05-16T10:15:10+00:00Added an answer on May 16, 2026 at 10:15 am

    We can use collections to store values to suit your purposes, but they need to be declared as SQL types:

    create type list_record is table of varchar2(128)
    /
    

    This is because we cannot use PL/SQL types in SQL statements. Alas this means we cannot use %TYPE or %ROWTYPE, because they are PL/SQL keywords.

    Your procedure would then look like this:

    DECLARE
        c_LIST list_record;
    BEGIN
    
        SELECT my_field 
        BULK COLLECT INTO c_LIST 
        FROM my_table
        WHERE some_field = some_value;
    
        -- try to check against list
        SELECT * FROM some_other_table
        WHERE some_critical_field IN ( select * from table (c_LIST);
    
    END;    
    

    “I see that you still had to perform a
    SELECT statement to populate the list
    for the IN clause.”

    If the values are in a table there is no other way to get them into a variable 🙂

    “I’m thinking that there’s a
    significant performance gain using
    this over a direct semi-join”

    Not necessarily. If you’re only using the values once then the sub-query is certainly the better approach. But as you want to use the same values in a number of discrete queries then populating a collection is the more efficient approach.

    In 11g Enterprise Edition we have the option to use result set caching. This is a much better solution, but one which is not suited for all tables.

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

Sidebar

Related Questions

Edit: Changed question title from Does C# allow method overloading, PHP style (__call)? -
EDIT : Changed title from inheritance to composition. Left body of question unchanged. I'm
EDIT: Changed title to actually be correct I'm trying to simulate a modal popup
Edit: Changed title to reflect both methods in post. I'm trying to compare two
EDIT:I've changed the title, because the issue had nothing to do with IE image.load()
EDIT: changed the title. I didn't know it at the time but this is
Edit: Changed the title. I'm less interested in the two segments being the same,
[EDIT: Changed title to better conceptualize the question.] The value of the attribute @xml:space
EDIT: SOLVED. Use any of the solutions below, but document.onload needs to be changed
[Edit] changed return 0 to return . Side effects of beinga Python n00b. :)

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.