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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:01:51+00:00 2026-05-22T12:01:51+00:00

I am writing some PL/SQL and found myself falling into a repeptitive pattern: cursor

  • 0

I am writing some PL/SQL and found myself falling into a repeptitive pattern:

cursor c_curs1 is
   select a, b, c
   from (...) big_subquery_1
   where big_subquery_1.a_ind = 'Y'

cursor c_curs2 is
   select a, b, c
   from (...) big_subquery_2
   where big_subquery_2.b_ind = 'R'

cursor c_curs3 is
   select a, b, c
   from (...) big_subquery_3
   where big_subquery_3.c_ind = 'M'

...
type t_curs1_tab is table of c_curs1;
type t_curs2_tab is table of c_curs2;
type t_curs3_tab is table of c_curs3;
...
v_curs1_results t_curs1_tab := t_curs1_tab();
v_curs2_results t_curs2_tab := t_curs2_tab();
v_curs3_results t_curs3_tab := t_curs3_tab();

Then when processing the results, I have code like this:

    open c_curs1;
    fetch c_curs1 bulk collect into v_curs1_results;
    close c_curs1;

    if v_curs1_results.first is not null and v_curs1_results.last is not null then
       for i in v_curs1_results.first .. v_curs1_results.last loop
           /*Do something with field a in the results
             Do something with field b in the results
             Do something with field c in the results*/
           ....
       end loop;
    end if;

The code in the processing loop is the same for all cursors, as all 3 cursors return a,b,c – the only difference being which cursor is referenced. I wanted to refactor this into some sort of generic result-set processor, but I’m stuck here:

procedure sp_process_collection(in_collection t_curs1_tab) is ...

I can only call this with v_curs1_results, I can’t call it with v_curs2_results or I get a PLS-00306 wrong number of types or arguments... compiler error. Is there any way to do this generically so I only have to write one collection processing procedure? I have this pattern of cursor (returning the same three columns, always the same types) appears in several other parts of the same package, and the processing loop, while semantically the same is sometimes written with slightly different code. I’d very much like to centralize the processing in one procedure, I just can’d figure out how to do it in PL/SQL. I know PL/SQL doesn’t have generics (Which I think would have made a Java/C# solution fairly trivial), but I’m wondering if there’s another way to approach this problem that I just haven’t thought of.

(using Oracle 10g)

  • 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-22T12:01:51+00:00Added an answer on May 22, 2026 at 12:01 pm

    If the resulting columns are the same, there’s no reason to have three TYPE declarations. You just have one TYPE. Whether you need one or more variables of that TYPE depends on whether you need to hold the different data sets concurrently.

    cursor c_curs1 is
       select a, b, c
       from (...) big_subquery_1
       where big_subquery_1.a_ind = 'Y'
    
    cursor c_curs2 is
       select a, b, c
       from (...) big_subquery_2
       where big_subquery_2.b_ind = 'R'
    
    cursor c_curs3 is
       select a, b, c
       from (...) big_subquery_3
       where big_subquery_3.c_ind = 'M'
    
    ...
    type t_curs_tab is table of c_curs1;
    ...
    v_curs_results t_curs_tab := t_curs_tab();
    ...
    open c_curs1;
    fetch c_curs1 bulk collect into v_curs_results;
    close c_curs1;
    ...
    open c_curs2;
    fetch c_curs2 bulk collect into v_curs_results;
    close c_curs2;
    ...
    open c_curs3;
    fetch c_curs3 bulk collect into v_curs_results;
    close c_curs3;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on some SQL code. I'm familiar with the syntax SELECT * FROM
I am writing some new SQL queries and want to check the query plans
I have seen majority of web programmers (writing some script with sql to make
I'm writing some JDBC code which calls a Oracle 11g PL/SQL procdedure which has
I'm writing some SQL queries with several subqueries and lots of joins everywhere, both
I'm writing some SQL for our lab, and I have it all done except
I'm writing some custom .Net extensions for SQL Server 2008. One of them is
I am writing some T-SQL which needs to enforce a minimum date value onto
I have been writing some queries about SQL Server in order to learn. I
I'm currently writing some installer script that fires SQL files against different database types

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.