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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:58:39+00:00 2026-05-11T23:58:39+00:00

I’ve got a PL/SQL package that returns a sys_refcursor based on the id that

  • 0

I’ve got a PL/SQL package that returns a sys_refcursor based on the id that you pass it. I’d like to iterate through some ids and create a new ref cursor with one column from the original result set repeated for each id. (Sort of a cross tab.) A very simplified version of the PL/SQL block looks like:

create or replace package body dashboard_package is

   procedure visits(RC in out sys_refcursor, IdNumber varchar2) as 
   BEGIN

      OPEN RC FOR 


      select *
  from (
        select cat, cat_order, subcat, label_text
               , trim(to_char(sum(v.current_month),'9,999,999,999')) current_month
               , trim(to_char(sum(v.ly_month),'9,999,999,999')) ly_month
               , trim(to_char(sum(v.ytd_tot),'9,999,999,999')) ytd_tot
               , trim(to_char(sum(v.lytd_tot),'9,999,999,999')) lytd_tot
               , trim(to_char(sum(v.ly_tot),'9,999,999,999')) ly_tot
          from dashboard v
         where v.id_number = IdNumber
         group by cat_order, subcat, cat, label_text

            union all
            ...
             ) a

     order by cat_order, subcat;

       END; 
END;

I think if I had something like this

create or replace procedure test_refcur is
   refCursorValue SYS_REFCURSOR;   
begin
   dashboard_package.visits(refCursorValue,12345);
   for cursrow in refCursorValue loop
      dbms_output.put_line(cursrow.ytd_tot);
   end loop;
end test_refcur;

working, I could take it from there… any thoughts? Or perhaps clarification on the question that I should be asking.

  • 1 1 Answer
  • 1 View
  • 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-11T23:58:40+00:00Added an answer on May 11, 2026 at 11:58 pm

    If you’re coming in with a number of IDs, then first prize would be to run only one SQL query to fetch the lot in one go, using a bulk in-bind for the IDs. This would probably require a modification to dashboard_package.visits, or writing a new version of the visits procedure to accept a PL/SQL table of IDs instead of a single ID.

    If your hands are tied WRT modifying dashboard_package, then you could write a pipelined function to return the rows for a set of IDs:

    -- create some helper types for the pipelined function
    create type visitobj as object
    (id             number
    ,cat            dashboard.cat%type
    ,cat_order      dashboard.cat_order%type
    ,subcat         dashboard.subcat%type
    ,label_text     dashboard.label_text%type
    ,current_month  varchar2(13)
    ,ly_month       varchar2(13)
    ,ytd_tot        varchar2(13)
    ,lytd_tot       varchar2(13)
    ,ly_tot         varchar2(13));
    create type visittable as table of visitobj;
    
    create or replace function test_refcur
       return visittable deterministic pipelined is
       refCursorValue SYS_REFCURSOR;
       cat            dashboard.cat%type;
       cat_order      dashboard.cat_order%type;
       subcat         dashboard.subcat%type;
       label_text     dashboard.label_text%type;
       current_month  varchar2(13);
       ly_month       varchar2(13);
       ytd_tot        varchar2(13);
       lytd_tot       varchar2(13);
       ly_tot         varchar2(13);
    begin
      for id in (/*iterate through the IDs*/) loop
       dashboard_package.visits(refCursorValue, id);
       loop
          fetch refCursorValue into cat, cat_order, subcat, label_text,
                                    current_month, ly_month, ytd_tot,
                                    lytd_tot, ly_tot;
          exit when refCursorValue%NOTFOUND;
          pipe row (visitobj (id, cat, cat_order, subcat, label_text,
                              current_month, ly_month, ytd_tot,
                              lytd_tot, ly_tot));
       end loop;
      end loop;
      return;
    end test_refcur;
    
    -- now you can simply do this:
    SELECT * FROM TABLE(test_refcur);
    

    (Of course, “/*iterate through the IDs*/” would be whatever method you want to use to gather the IDs for which the function should be called – e.g. could be a PL/SQL table of IDs, or perhaps another query).

    Again I’d stress that “first prize” is to not do any of this extra work at all – just have a dashboard_package.visits that does it all in one SQL.

    On a side note, trim(to_char(sum(v.ly_tot),'9,999,999,999')) can be simplified to to_char(sum(v.ly_tot),'FM9,999,999,999'). Also, if you use the format 'FM9G999G999G999' instead, it will be non-locale-specific.

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

Sidebar

Ask A Question

Stats

  • Questions 214k
  • Answers 214k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer mb_internal_encoding() doesn't effect the output of your scripts per se,… May 12, 2026 at 10:46 pm
  • Editorial Team
    Editorial Team added an answer Use array_unshift($array, $item); $arr = array('item2', 'item3', 'item4'); array_unshift($arr ,… May 12, 2026 at 10:46 pm
  • Editorial Team
    Editorial Team added an answer Bigint is an integer datatype, so yeah, that won't work… May 12, 2026 at 10:46 pm

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS
I want use html5's new tag to play a wav file (currently only supported

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.