mysqlmysql-error-1064create-function

MySQL ERROR 1064 in CREATE FUNCTION


I am unable to debug the code for CREATE FUNCTION. It gives the following error:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 16

This is the code.

DELIMITER $$
CREATE FUNCTION CHECK_STATUS(SAL FLOAT) RETURNS VARCHAR(10)
DETERMINISTIC
BEGIN
    DECLARE STATUS VARCHAR(10);
    SET STATUS = "";
    IF (SAL > 70000) THEN
    SET STATUS = "A CLASS";
    ELSEIF (SAL > 50000) THEN
    SET STATUS = "B CLASS";
    ELSE IF (SAL > 30000) THEN 
    SET STATUS = "C CLASS";
    ELSE
    SET STATUS = "D CLASS";
    END IF;
RETURN STATUS; # This is line 16
END; 
$$

PS: I have seen other question with same title but they were about the DELIMITER so they didn't help. My MySQL version is 5.7.19


Solution

  • It will work if you change ELSE IF to ELSEIF. It is treated as ELSE and then unclosed IF clause, without END IF.