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 > DB2 > Returning more than one ResultSet from Stored Procedure

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-06-10, 08:16
sunny8107 sunny8107 is offline
Registered User
 
Join Date: Mar 2010
Posts: 7
Question Returning more than one ResultSet from Stored Procedure

All,
It works fine when I return one ResultSet from a Procedure, but now when I return more than ResultSet. Below is my procedure:

create procedure show_employee_department()
dynamic result sets 2
begin
declare c_emp cursor with return for select * from employee;
open c_emp;

delcare c_dept cursor with return for select * from department;
open c_dept;
end

I get this error:
SQL0104N An unexpected token "delcare" was found following "loyee;
open c_emp;

". Expected tokens may include: "DECLARE

My Statement Termination character is '@'.

What am I missing here? Thanks in advance!
Reply With Quote
  #2 (permalink)  
Old 04-06-10, 08:50
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Look at the syntax diagram for creating a store procedure. The DECLARE CURSOR statements must all be at the beginning.

Try this:

Code:
create procedure show_employee_department()
dynamic result sets 2
begin
declare c_emp cursor with return for select * from employee;
delcare c_dept cursor with return for select * from department;


open c_emp;

open c_dept;
end
Andy
Reply With Quote
  #3 (permalink)  
Old 04-06-10, 08:55
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,194
Sequence of statements in a compound SQL statement are fixed.
For example, all DECLARE-CURSOR-statements should be placed before SQL-procedure-statements(including open cussor statement).

Please see more detaile in IBM DB2 9.7 for Linux, UNIX and Windows Information Center
Reply With Quote
  #4 (permalink)  
Old 04-06-10, 12:27
sunny8107 sunny8107 is offline
Registered User
 
Join Date: Mar 2010
Posts: 7
Thanks guys.
Reply With Quote
  #5 (permalink)  
Old 04-11-10, 14:09
DBFinder DBFinder is offline
Registered User
 
Join Date: Sep 2008
Location: Toronto,Canada
Posts: 606
Quote:
Originally Posted by sunny8107 View Post
All,
It works fine when I return one ResultSet from a Procedure, but now when I return more than ResultSet. Below is my procedure:

create procedure show_employee_department()
dynamic result sets 2
begin
declare c_emp cursor with return for select * from employee;
open c_emp;

delcare c_dept cursor with return for select * from department;
open c_dept;
end

I get this error:
SQL0104N An unexpected token "delcare" was found following "loyee;
open c_emp;

". Expected tokens may include: "DECLARE

My Statement Termination character is '@'.

What am I missing here? Thanks in advance!

Did anyone notice spelling mistake above ??


regards
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