I am having a problem with a nested SQL Procedure on DB2 V8.2.1 on Windows.
This simple-looking proc is giving me this error message when I try to build
it in the Development Center:
RHINO.CALLED01: 18: [IBM][CLI Driver][DB2/NT] SQL0104N An unexpected token
"<cursor declaration>" was found following "". Expected tokens may include:
"<SQL statement>". LINE NUMBER=18 SQLSTATE=42601
Here is the source code for the proc; line 18 is the line that begins
"declare cursor2 cursor".
-----------------------
CREATE PROCEDURE RHINO.CALLED01 (IN in_sex char(1), IN in_edlevel smallint)
language SQL
dynamic result sets 2
------------------------------------------------------------------------
-- SQL Stored Procedure
------------------------------------------------------------------------
BEGIN
declare cursor1 cursor with return to caller for
select empno, lastname, salary, bonus, comm
from emp
where sex = in_sex
and edlevel = in_edlevel
order by empno;
open cursor1;
declare cursor2 cursor with return to caller for
select count(*)
from emp
where sex = in_sex
and edlevel = in_edlevel;
open cursor2;
END
-----------------------
This proc compiled and ran fine before I added the second cursor. I can't
figure out what's wrong. The two top candidates for the cause are:
1. It is not permissible to have two result sets in an SQL proc. That seems
unlikely because the "dynamic result sets" clause permits any positive
integer, as far as I can tell from the manual.
2. My structure is off somehow: maybe I need to have intervening statements
of some kind between the two cursors. If so, what am I missing?
Can anyone tell me what's wrong with this procedure? I have tried googling
and didn't find anything useful and haven't seen anything that helped in the
manuals.
--
Rhino
---
rhino1 AT sympatico DOT ca
"There are two ways of constructing a software design. One way is to make it
so simple that there are obviously no deficiencies. And the other way is to
make it so complicated that there are no obvious deficiencies." - C.A.R.
Hoare