What's wrong with the following DB2 function?
CREATE FUNCTION MIGRATION.determineToTaxService
(DIGI_NAAR_VLG CHAR, DIGI_VAN_VLG CHAR, NAARVLG CHAR)
RETURNS CHAR
BEGIN ATOMIC
DECLARE returnValue CHAR;
SET returnValue = '0';
IF (DIGI_NAAR_VLG = '1') THEN
SET returnValue = '1';
ELSEIF (DIGI_VAN_VLG = '1') THEN
SET returnValue = '1';
ELSEIF (NAARVLG = '1') THEN
SET returnValue = '1';
END IF;
RETURN returnValue;
END;
I'm getting this error:
An unexpected token "CHAR" was found following " DECLARE returnValue". Expected tokens may include: "END-OF-STATEMENT". SQL Code: -104, SQL State: 42601
Error occured in:
CREATE FUNCTION MIGRATION.determineToTaxService
(DIGI_NAAR_VLG CHAR, DIGI_VAN_VLG CHAR,
NAARVLG CHAR)
RETURNS CHAR
BEGIN ATOMIC
DECLARE returnValue CHAR
I can't really figure it out. It's also not running if I remove the if and elsif statements so the problem shouldn't be there.
The terminating character is wrong:
You can call it from the command line like:
A trick is to end the lines with a comment like:
Then you can continue using ; as a statement terminator
You might want to simplify the function, something like:
should do