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 8345117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:35:04+00:00 2026-06-09T06:35:04+00:00

I need to optimize a PL/SQL function that is currently like that: CREATE OR

  • 0

I need to optimize a PL/SQL function that is currently like that:

CREATE OR REPLACE FUNCTION tkt_get_underlying(n_input number)
RETURN t_table_of_number
IS
    ret t_table_of_number;
    CURSOR c IS SELECT n_number FROM t_table WHERE n_prop_1=n_input OR n_prop_2=n_input OR n_prop_3=n_input;
BEGIN
    ret :=  t_table_of_number();

    OPEN c;
        FETCH c BULK COLLECT INTO ret;
    CLOSE c;

    RETURN ret;
END;

I want to be able to give an array as argument, however, I don’t know how to build my cursor to take to array. I think I could use the IN statement, but could you help me settle this down please ?

EDIT:

According to solution provided by Justin Cave, it would become:

CREATE OR REPLACE FUNCTION tkt_get_underlying(n_inputs t_table_of_number)
RETURN t_table_of_number
IS
    ret t_table_of_number;
    CURSOR c IS SELECT n_number FROM t_table WHERE n_prop_1 IN (SELECT column_value FROM TABLE(n_inputs))
                                             OR n_prop_2 IN (SELECT column_value FROM TABLE(n_inputs))
                                             OR n_prop_3 IN (SELECT column_value FROM TABLE(n_inputs));
BEGIN
    ret :=  t_table_of_number();

    OPEN c;
        FETCH c BULK COLLECT INTO ret;
    CLOSE c;

    RETURN ret;
END;

However, the multiple SELECT column_value FROM TABLE(n_inputs) slow the entire function. How can I improve that ?

  • 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-09T06:35:05+00:00Added an answer on June 9, 2026 at 6:35 am

    If you want to pass in a collection of n_input values and return the same t_table_of_number collection (i.e. you don’t need to know which element of the output array was associated with which element of the input array)

    CREATE OR REPLACE FUNCTION tkt_get_underlying(p_inputs t_table_of_number)
    RETURN t_table_of_number
    IS
        ret t_table_of_number;
        CURSOR c 
            IS SELECT n_number 
                 FROM t_table 
                WHERE n_prop IN (SELECT column_value 
                                   FROM TABLE( p_inputs ) );
    BEGIN
        OPEN c;
            FETCH c BULK COLLECT INTO ret;
        CLOSE c;
    
        RETURN ret;
    END;
    

    This assumes that the number of elements that is going to potentially be inserted into the ret collection is still reasonable to hold in PGA memory simultaneously. Depending on the situation, you may want to transform this into a pipelined table function in order to limit the amount of PGA memory required.

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

Sidebar

Related Questions

I'm in a need to optimize this really tiny, but pesky function. unsigned umod(int
I am have a lot of code that I need to optimize and make
I've got an initializer method that does a silly thing. I need to optimize
I have a webpage that is taking way too long and need to optimize
I want to optimize some of the SQL and just need an opinion on
I have an SQL query that I am looking to optimize. SELECT * FROM
I was given a SQL query, saying that I have to optimize this query.
I need to optimize a feature which displays the number of alarms for the
I have this one gigantic complex LINQ to SQL query that I need to
I need to optimize our web service, but don't know where to begin. We're

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.