Hi,
on db2 v8.2 FP9 on Windows XP I would like to write a store procedure which will declare cursor according to input parameter using if logic.
Sample:
Code:
CREATE PROCEDURE ADMIN.TEST (
IN InParameter CHAR(1) )
P1: BEGIN
IF InParameter = '1' THEN
DECLARE cursor1 CURSOR WITH RETURN FOR SELECT 'A' FROM SYSIBM.SYSDUMMY1;
ELSE
DECLARE cursor1 CURSOR WITH RETURN FOR SELECT 'B' FROM SYSIBM.SYSDUMMY1;
END IF;
OPEN cursor1;
END P1
@
Note: Select statements in above sample are simplified samples. In my case there are two different select statements.
I get error:
================================================== =====================
C:\aaa>DB2 -TD@ -F A.SQL
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0104N An unexpected token "<cursor declaration>" was found following "".
Expected tokens may include: "<SQL statement>". LINE NUMBER=7.
SQLSTATE=42601
================================================== =====================
It looks like there is some problem using if and declare cursor. Any idea what is wrong with my procedure?
Thanks,
Grofaty