If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > how to return ref cursor for more than one table?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-09-10, 04:27
sanoj_av sanoj_av is offline
Registered User
 
Join Date: Dec 2007
Posts: 11
how to return ref cursor for more than one table?

Hi

I am new to Oracle. I have a procedure getLoanInfo that returns a recordset as ref cursor. I just want to call it from the PL/SQL.
my doubt is regarding the declaration of the tblLoans%rowtype. Here tblLoans is one table but the result set returned by the proc contains a differrent data set. ie, it is the result set from more than one table.
So how do I specify it in the %rowtype. Or any other way. I tried it in the following way and I got an error




declare
type r_cursor is REF CURSOR;
c_var r_cursor;
res tblLoans%rowtype;
begin
pkgmain.getLoanInfo('AK','AK020',NULL,c_var);
loop
fetch c_var into res;
exit when c_var%notfound;
dbms_output.put_line(res.closingBal);
end loop;
close c_var;
end;


ORA-00932: inconsistent datatypes: expected - got -
ORA-06512: at line 8
00932. 00000 - "inconsistent datatypes: expected %s got %s"
Reply With Quote
  #2 (permalink)  
Old 02-09-10, 11:03
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
Cool OK, try this.

Assuming "res.closingbal" is always returned:
Code:
DECLARE
  TYPE r_cursor IS REF CURSOR;
  c_var  R_CURSOR;
BEGIN
  pkgmain.Getloaninfo('AK','AK020',NULL,c_var);
  
  FOR res IN c_var LOOP
    dbms_output.Put_line(res.closingbal);
  END LOOP;
END;
/
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #3 (permalink)  
Old 02-09-10, 23:43
sanoj_av sanoj_av is offline
Registered User
 
Join Date: Dec 2007
Posts: 11
But my question is how to define the Res.
In the example it is defined as res tblLoans%rowtype;
But it is throwing error as the result set is not in the same structure of tblLoans Table.
It is the combination of columns from five different tables by joining.


Any Idea?
Reply With Quote
  #4 (permalink)  
Old 02-10-10, 00:32
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,407
PL/SQL FAQ - Oracle FAQ

Code:
DECLARE
  v_emp emp%ROWTYPE;
BEGIN
In sample above, is EMP a Table or View?
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On