Gouri Yashodhan
Gouri Yashodhan

Reputation: 81

DB2 stored proc if statement string comparison

I am working on a DB2 stored procedure where I want to perform the following :

 CREATE PROCEDURE TestProc ( IN IN_NBR CHAR(20))
 ISOLATION LEVEL CS
 VALIDATE BIND
 RESULT SETS 1

P1: BEGIN

IF ((SUBSTR(IN_NBR,1,2) != 'IO') 
    OR (SUBSTR(IN_NBR,1,2) != 'DO'))
THEN 
    SELECT *
    FROM AB.WC_TEM WC
    WHERE WC.CAT_NBR = IN_NBR
    WITH UR; 
END IF;

END P1

This fails to even deploy.

Upvotes: 0

Views: 781

Answers (1)

mao
mao

Reputation: 12287

To save time , always write your Db2-server operating-system and Db2-version when asking for help. The answer can depend on those facts.

Ensure your statement terminator is not default (in the example below I use @ for the terminator), and follow the rules for using cursors in SQL procedures to return result-sets to client or caller:

Example:

CREATE or replace PROCEDURE TestProc ( IN IN_NBR CHAR(20) )
 ISOLATION LEVEL CS
 VALIDATE BIND
 language sql
 specific TestProc
 dynamic RESULT SETS 1

BEGIN
    declare c1 cursor for SELECT * FROM AB.WC_TEM WHERE CAT_NBR = IN_NBR  with ur;

    IF ((SUBSTR(IN_NBR,1,2) != 'IO') OR (SUBSTR(IN_NBR,1,2) != 'DO'))
    THEN
        open c1;
    END IF;

END
@

Upvotes: 4

Related Questions