Refcursor with returning resultset [message #618122] |
Tue, 08 July 2014 05:22 |
|
sss111ind
Messages: 634 Registered: April 2012 Location: India
|
Senior Member |
|
|
Whether one refcursor may be used once or mutliple times for different result sets.
Here we have used single refcursor with mutliple result sets. Is there any problem of doing that.
Please suggest.
create or replace package test_refcursor is
type t1 is ref cursor;
procedure get_emp(p_deptno number,c1 out t1);
procedure get_dept(p_deptno number,c1 out t1);
end;
create or replace package body test_refcursor is
procedure get_emp(p_deptno number,c1 out t1)
is begin
open c1 for select * from emp where deptno=p_deptno;
null;
end;
procedure get_dept(p_deptno number,c1 out t1)
is begin
open c1 for select * from dept where deptno=p_deptno;
null;
end;
end;
declare
cc1 test_refcursor.t1;
begin
test_refcursor.get_emp('20',cc1);
test_refcursor.get_dept('20',cc1);
end;
Regards,
Nathan
[Updated on: Tue, 08 July 2014 05:57] Report message to a moderator
|
|
|
|
|
|
|
Re: Refcursor with returning resultset [message #618144 is a reply to message #618132] |
Tue, 08 July 2014 07:34 |
Solomon Yakobson
Messages: 3273 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
sss111ind wrote on Tue, 08 July 2014 07:15I excepted this error 'maximum open cursors exceeded ' after executing this because so may cursor were opened and nothing was closed .
You completely misunderstand cursor concepts. Example you posted opens same cursor many times. You really need to read documentation. Opening and Closing Cursor Variables:
Quote:You need not close a cursor variable before reopening it (that is, using it in another OPEN FOR statement). After you reopen a cursor variable, the query previously associated with it is lost.
SY.
|
|
|
Re: Refcursor with returning resultset [message #618222 is a reply to message #618144] |
Wed, 09 July 2014 09:26 |
|
sss111ind
Messages: 634 Registered: April 2012 Location: India
|
Senior Member |
|
|
So by declaring one ref cursor,can we use it again and again like as follows,
create or replace package test_refcursor is
type t1 is ref cursor;
procedure get_proc1(p_deptno number,c1 out t1);
procedure get_proc2(p_deptno number,c1 out t1);
.
.
.
.
procedure get_proc10000(p_deptno number,c1 out t1);
end;
[Updated on: Wed, 09 July 2014 09:27] Report message to a moderator
|
|
|
|
Re: Refcursor with returning resultset [message #618224 is a reply to message #618223] |
Wed, 09 July 2014 09:59 |
Solomon Yakobson
Messages: 3273 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
Not sure what you mean. There are no issues with:
create or replace package test_refcursor is
type t1 is ref cursor;
procedure get_proc1(p_deptno number,c1 out t1);
procedure get_proc2(p_deptno number,c1 out t1);
.
.
.
.
procedure get_proc10000(p_deptno number,c1 out t1);
end;
SY.
|
|
|
|
|
Re: Refcursor with returning resultset [message #618228 is a reply to message #618222] |
Wed, 09 July 2014 11:01 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
sss111ind wrote on Wed, 09 July 2014 19:56So by declaring one ref cursor,can we use it again and again
If I understand correctly, Michel pointed out already that you are just declaring a ref cursor TYPE which you are using as an OUT parameter to hold the resultset of each OPEN CURSOR FOR statement. You could say the ref cursors are different when you have something like this in your code for each procedure
var_cursor SYS_REFCURSOR;
Perhaps I got it right, perhaps not. Michel, did I get it correct? Or did you mean something else. Since it got a bit confusing in last two posts of yours and SY's.
|
|
|
|
|
|
Re: Refcursor with returning resultset [message #618290 is a reply to message #618285] |
Thu, 10 July 2014 06:04 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
sss111ind wrote on Thu, 10 July 2014 16:11Then If weak refcursor gives so much flexibility why to use strong refcursor.
Think about returning dataset to a GUI, and you use weak type ref cursor, so GUI has no idea what sort of dataset would be returning to it. How would a frontend developer know what to design to display the dataset? And there are many other things, may be this would answer your doubts.
|
|
|