简单的mysql函数语法错误1064

时间:2022-03-13 22:35:05

I cant figure outt the error in this function that i wrote. I suspect that it must be something with type casting. i tried to comment part by part to see where the error may be and it was somewhere after the first IF and before return. I would really appreciate if someone could help me figure it out. the error is 1064 and it says that syntax is missing near ' ' line 33.

我无法弄清楚我写的这个函数的错误。我怀疑它必须是类型铸造的东西。我试图逐个评论,看看错误可能在哪里,它是在第一个IF之后和返回之前的某个地方。如果有人能帮助我搞清楚,我真的很感激。错误是1064,它表示在第33行附近缺少语法。

 DELIMITER $$



CREATE DEFINER=`root`@`localhost` FUNCTION `substation1`(`subofficecode` INT,`productcat` VARCHAR(5),`ALN` INT(1)) RETURNS VARCHAR(10)

READS SQL DATA

BEGIN

 DECLARE substation_ID VARCHAR(10);

 DECLARE pcat VARCHAR(2);

 DECLARE  i INT;



 IF (LENGTH (subofficecode) < 3) THEN

            SET substation_ID= CONCAT ('0',subofficecode);

 ELSE IF (LENGTH (subofficecode) < 2) THEN

            SET substation_ID= CONCAT ('00',subofficecode);

 ELSE

            SET substation_ID= CONCAT('',subofficecode);

 END IF;



 IF (STRCMP(productcat,'REF')=0) THEN

            SET pcat = '11';

 ELSE IF (STRCMP(productcat,'DF')=0) THEN

            SET pcat='12';

 ELSE IF (STRCMP(productcat,'MWO')=0) THEN

            SET pcat='13';

 ELSE IF (STRCMP(productcat,'WM')=0) THEN

            SET pcat='14';

 ELSE IF (STRCMP(productcat,'SPLIT')=0) THEN

            SET pcat='15';

 ELSE

            SET pcat='16'; 

 END IF;



SET i=(SELECT MAX(substationid) FROM substation) + 1;

SET substation_ID=CONCAT(substation_ID,pcat,ALN,i);



RETURN substation_ID;



END$$



DELIMITER ;

1 个解决方案

#1


0  

At the bare minimum, when chaining conditions in an IF statement, the right syntax is ELSEIF not ELSE IF.

至少,当在IF语句中链接条件时,正确的语法是ELSEIF而不是ELSE IF。

IF search_condition THEN statement_list
    [ELSEIF search_condition THEN statement_list] ...
    [ELSE statement_list]
END IF

See http://dev.mysql.com/doc/refman/5.0/en/if.html for the supported syntax

有关支持的语法,请参阅http://dev.mysql.com/doc/refman/5.0/en/if.html

#1


0  

At the bare minimum, when chaining conditions in an IF statement, the right syntax is ELSEIF not ELSE IF.

至少,当在IF语句中链接条件时,正确的语法是ELSEIF而不是ELSE IF。

IF search_condition THEN statement_list
    [ELSEIF search_condition THEN statement_list] ...
    [ELSE statement_list]
END IF

See http://dev.mysql.com/doc/refman/5.0/en/if.html for the supported syntax

有关支持的语法,请参阅http://dev.mysql.com/doc/refman/5.0/en/if.html