lundi 31 décembre 2018

db2 - CASE WHEN or IF Statement in CREATE FUNCTION

Hi I've got a problem managing CASE WHEN or IF Statements in a CREATE FUNCTION Call in DB2 I tried this Statement:

CREATE OR REPLACE FUNCTION NAECHSTES_DATUM(PARAM1 CHAR(6), PARAM2 DATE)
RETURNS DATE
LANGUAGE SQL
BEGIN
    DECLARE BASEDATE DATE;
    DECLARE THATDATE DATE;
    SET BASEDATE = TO_DATE(CONCAT(PARAM1,CAST(YEAR(PARAM2) AS CHAR(4))),'DD.MM.YYYY');
    IF (BASEDATE >= PARAM2) 
    THEN SET THATDATE = BASEDATE;
    ELSE SET THATDATE = BASEDATE + 1 YEAR;
    END IF;
    RETURN THATDATE;
END 

I get this error

[-104] Auf "+ 1 YEAR" folgte das unerwartete Token "END-OF-STATEMENT". Mögliche Tokens: " END IF".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.14.113

Similar result when I use CASE WHEN.

Do you know where the problem could be?

Aucun commentaire:

Enregistrer un commentaire