Search code examples
stored-proceduresdb2iseries-navigator

DB2 error : Keyword SELECT not expected. Valid tokens: FOR WITH WITHOUT


I am trying to execute the following stored procedure on db2 database using iSeries Navigator:

CREATE PROCEDURE ZSPPQDELETEUSERIDBA ( 
    IN P_USERID CHAR(10) , 
    IN P_BUSINESSAREA CHAR(10))
    DYNAMIC RESULT SETS 1 

    LANGUAGE SQL 
    SPECIFIC ZSPPQDELETEUSERIDBA 
    NOT DETERMINISTIC 
    MODIFIES SQL DATA 
    CALLED ON NULL INPUT 
    SET OPTION  ALWBLK = *ALLREAD , 
    ALWCPYDTA = *OPTIMIZE , 
    COMMIT = *CS , 
    CLOSQLCSR = *ENDMOD , 
    DECRESULT = (31, 31, 00) , 
    DFTRDBCOL = *NONE , 
    DYNDFTCOL = *NO , 
    DYNUSRPRF = *USER , 
    RDBCNNMTH = *RUW ,
    SRTSEQ = *HEX 
    P1 : BEGIN 

    DECLARE TOTALCNT INTEGER DEFAULT 0 ; 

    DECLARE C1 CURSOR WITH RETURN TO CALLER
    SELECT Count (*) FROM USERBUSINESSAREA
     WHERE USERID            = P_USERID
       AND BUSINESSAREA = P_BUSINESSAREA;

    OPEN C1;
       FETCH C1 INTO TOTALCNT;

    IF ( TOTALCNT = 1) THEN 
        DELETE 
          FROM  USERBUSINESSAREA     
         WHERE  USERID       = P_USERID
           AND  BUSINESSAREA = P_BUSINESSAREA;
    END IF;
    END P1  ;

I am getting the following error when I try to execute the above procedure:

SQL State: 42601
Vendor Code: -199
Message: [SQL0199] Keyword SELECT not expected. Valid tokens: FOR WITH WITHOUT. Cause . . . . . :   The keyword SELECT was not expected here.  A syntax error was detected at keyword SELECT.  The partial list of valid tokens is FOR WITH WITHOUT. This list assumes that the statement is correct up to the unexpected keyword.  The error may be earlier in the statement but the syntax of the statement seems to be valid up to this point. Recovery  . . . :   Examine the SQL statement in the area of the specified keyword.  A colon or SQL delimiter may be missing. SQL requires reserved words to be delimited when they are used as a name. Correct the SQL statement and try the request again.

What's going wrong here?


Solution

  • I found out where the problem is.I was supplying the wrong input values for the stored procedure(i.e one in place of another..data types are different). That caused the issue. Now it is resolved