简体   繁体   English

简单的mysql函数语法错误1064

[英]simple mysql function syntax error 1064

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. 我试图逐条注释,以查看错误可能在哪里,它在第一个IF之后到返回之前的某个地方。 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. 错误为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 ;

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM