Processing different cursor types with the same procedure/function

From: Martin Bertolino <martinbertolino_at_yahoo.com>
Date: 12 Aug 2002 08:03:19 -0700
Message-ID: <95be4880.0208120703.68a05c15_at_posting.google.com>


I have some PL/SQL code that has a few cursors that are almost identical - join same tables, return same set of columns - but differ only in their where clauses. For example:

and the other cursor is:

Notice that the only change is the where clause on the sss/identifier column.

The rows returned by these cursors are then processed in a construct such as:

for it in v_employee_company_cursor loop

  • processing code (repeated many times for each cursor type) end loop;

The problem I have is that I have to have a loop for each of the different cursors but the code within the loop block is identical.

I would like to be able to factor out this code into a generic function so I do not have repeated code and when I make changes or fixes they are done in only one place.

I looked at cursors with specified return type, but this can only be a table type so I did not know how to do this with joins or with subsets of all the columns. I could also create a procedure/function that takes one argument for each column in the select but this seemed error prone and difficult to maintain.

Does anybody have any suggestions on how could this be accomplished? This is just one case of this scenario, my application has other sections that suffer from this code repetition that I would like to avoid.

Thanks in advance

Martin Bertolino
'martinbertolino'||'_at_'||'yahoo'||'.'||'com' Received on Mon Aug 12 2002 - 17:03:19 CEST

Original text of this message