Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> PL/SQL: cursor variables can point to cursors?
I have a PL/SQL-Code fragement that does some deeds on data which are
fetched via cursors. The deeds are identical to all cursors, so it would
be nice if I could open "the right" cursor and then proceed with code
that processes the data from just this opened cursor.
To illustrate this: I would need a construct like this:
cursor cu2
is select text from other_textblocks;
x_which_cursor := 1;
if x_which_cursor = 1 then
cuText := cu1;
else
cuText := cu1;
end if;
open cuText;
loop
fetch cuText into x_text;
exit when cuText%NOTFOUND;
end loop;
close cuText;
So, depending on an if-construct, I want to open either Cursor cu1 or Cursor cu2. Can I do something like this in a syntactically "nice-to- look-at" way?
One (not so beautiful) way I can think of is this:
cursor cu2
is select text from other_textblocks;
x_which_cursor := 1;
if x_which_cursor = 1 then
open cu1;
else
open cu2;
end if;
loop
if x_which_cursor = 1 then
fetch cu1 into x_text;
exit when cu1%NOTFOUND;
else
fetch cu2 into x_text;
exit when cu2%NOTFOUND;
end if;
end loop;
if x_which_cursor = 1 then
close cu1;
else
close cu2;
end if;
I would need something like a cursor variable, but instead of assigning a SQL-Select to a cursor variable, I would need to assign an explicit cursor to such a cursor variable. This seems not to be possible, according to my available documentation.
BTW:
Thanx a lot for all useful hints!
Alex
Received on Tue Dec 03 2002 - 05:34:54 CST