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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:45:28+00:00 2026-05-11T03:45:28+00:00

I have this problem I’m hoping someone knows the answer to. I have an

  • 0

I have this problem I’m hoping someone knows the answer to. I have an oracle stored procedure that takes a customer id and returns all the customer’s orders in a ref_cursor. Oversimplifying it, this is what I have:

Orders - orderId - siteID  Customers - siteID - Name  GetOrder(siteID, outCursor) /* returns all orders for a customer */ 

Now, I need to write another procedure that takes a customer name and does a LIKE query to get all custIds, then I need to reuse the GetOrder method to return all the orders for the custIds found, something like this:

   PROCEDURE GetOrderbyCustName(       p_name       IN        VARCHAR2,       curReturn    OUT       sys_refcursor    )    IS       siteid    number;    BEGIN       FOR rec in SELECT site_id FROM customers WHERE name LIKE p_name       LOOP        -- This will replace curReturn in each iteration       -- how do I append instead?         GetOrder(rec.site_id,                    curReturn                   );       END LOOP;    END GetOrderbyCustName; 

My question is, how do I append the return of GetOrder to curReturn in each iteration? As it’s written right now it overwrites it in each cycle of the loop. Thanks!!

  • 1 1 Answer
  • 2 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. 2026-05-11T03:45:29+00:00Added an answer on May 11, 2026 at 3:45 am

    If the query is simple, I would say go with Tony’s answer. This is not only simple but likely to perform better than executing one query for each siteID.

    If it is fairly complex then it might be worth some extra effort to reuse the GetOrder procedure so you only have to maintain one query.

    To do this, you would need to actually fetch the data from the refcursor on each iteration of the loop, and put it into some other data structure.

    One option, if it makes sense for the interface, is to change GetOrderbyCustName to have a PL/SQL index-by table as its output parameter instead of a refcursor. Append to that table on each iteration through the loop.

    If you really need to return a refcursor, you can use a nested table type instead and then return a cursor querying that nested table. Something like this (not tested code):

    CREATE TYPE number_table_type AS TABLE OF NUMBER;  PROCEDURE GetOrderbyCustName(       p_name       IN        VARCHAR2,       curReturn    OUT       sys_refcursor    )    IS       cursor_source_table  number_table_type := number_table_type();       single_site_cursor  sys_refcursor;       orderID  NUMBER;    BEGIN       FOR rec in SELECT site_id FROM customers WHERE name LIKE p_name       LOOP        -- This will replace curReturn in each iteration       -- how do I append instead?         GetOrder(rec.site_id,                    single_site_cursor                   );          -- Fetch all rows from the refcursor and append them to the nested table in memory         LOOP           FETCH single_site_cursor INTO orderID;           EXIT WHEN single_site_cursor%NOTFOUND;           cursor_source_table.extend();           cursor_source_table( cursor_source_table.COUNT+1) := orderID;         END LOOP;       END LOOP;        OPEN curReturn FOR         SELECT * FROM TABLE( cursor_source_table );     END GetOrderbyCustName; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this problem that I can ref a button for control it. I
I have this problem: I need to validate that files have not been uploaded
I have this problem that when I setframe of the parent view of the
I have this problem, I load a page using JQuery ajax, now within that
I have this problem that i have code like this in many of my
I have this problem that drives me mad, so I am here to ask
I have this problem: Well, the words in the article are ClickableSpans that change
i have this problem: I have created a bash script that performs some tasks.
I have this problem that I'm registering my Broadcast receiver for AlarmManager in the
I have this problem that i want to transfer specific ( yet not that

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.