DB2 makes the wrong choice in an IF statement when I use IF, IN and SIGNAL together. It always choose the first IF.
I think I found out a bug in DB2, but I'd like to know if I'm doing something wrong. I built a procedure with some IF-ELSEIF statements. If the last test in ELSEIF is an IN operator, DB2 always goes to the first condition, even if it is false.
For example:
CREATE PROCEDURE sp_dummy(
IN p_x CHAR(1))
LANGUAGE SQL
MODIFIES SQL DATA
NOT DETERMINISTIC
BEGIN ATOMIC
IF p_x = 'A' THEN
SIGNAL SQLSTATE '70001' SET MESSAGE_TEXT = 'px = a';
ELSEIF p_x = 'B' THEN
SIGNAL SQLSTATE '70002' SET MESSAGE_TEXT = 'px = b';
ELSEIF p_x IN ('X','Y') THEN
SIGNAL SQLSTATE '70003' SET MESSAGE_TEXT = 'px in (x,y)';
END IF;
END@
And these returns:
call sp_dummy('A') --> 'px = a'
call sp_dummy('B') --> 'px = b'
call sp_dummy('X') --> 'px = a' it's wrong, it should have returned 'px in (x,y)'
call sp_dummy('Y') --> 'px = a' it's wrong, it should have returned 'px in (x,y)'
My DB2 version is v8.1.0.64 FixPak 7 and the server is Linux (SUSE Enterprise Server 9)
please help me,
thanks.