Hi hope you guys can help.
I am trying to throw an error Message inside a Function if the Input (INT) isn't equal to length 8.
My Code:
DELIMITER $$
CREATE FUNCTION test(a INT)
RETURNS INT
BEGIN
DECLARE ret INT;
IF LENGTH(CONVERT(a, CHAR)) != 8 THEN SIGNAL SQLSTATE '4500' SET MESSAGE_TEXT = 'need to be 8!';
END IF;
IF a <= 20000000 THEN SET ret = 1;
ELSEIF a > 20000000 AND a <= 30000000 THEN SET ret = 2;
ELSE SET ret = 3;
END IF;
RETURN ret;
END;
$$
DELIMITER ;
Unfortunately when i create the Function it instantly throws the error message and doesn't wait for the condition. So when i am trying to run the Code it says:
Error Code: 1407. Bad SQLSTATE: '4500'
How can i solve that??