I'm trying to create a function in MySQL, but getting a syntax error. This is my function:
DELIMITER $$
CREATE FUNCTION gg ()
RETURNS char(8)
DETERMINISTIC
BEGIN
DECLARE cod varchar(8);
select RIGHT(MAX(idCurso),7) into cod from Curso;
IF cod is null then
set cod = 'C' + right('0000000' + convert(varchar(7),1),7);
else
set cod = 'C' + right('0000000' + convert(varchar(7), @id +1),7)
return cod;
END$$
DELIMITER ;
I am getting this error in the set cod after the if cod is null then:
"cod" is not valid at this position, expecting an identifier
What am I doing wrong?
set cod = 'C' + right('0000000' + convert(varchar(7),1),7);+for concatenation; but it's been a while since I checked. Also, it looks like the arguments forCONVERTmight be backwards...and you have noEND IFMake sure you are using documentation for MySQL, not MSSQL, nor Oracle, nor sqlite, etc..