Error de sintaxis para la función MySQL [cerrado]

DELIMITER $$

CREATE FUNCTION ecmsbackoffice.getSequence($delimeter VARCHAR(20)) RETURNS VARCHAR(20)
BEGIN
DECLARE result VARCHAR(20);
SET result = 0;

IF (delimeter='B') THEN UPDATE id_generator SET seq_currval=(seq_currval+1) WHERE seq_name='B';
ELSE IF (delimeter='D') THEN UPDATE id_generator SET seq_currval=(seq_currval+1) WHERE seq_name='D';
ELSE IF (delimeter='C') THEN UPDATE id_generator SET seq_currval=(seq_currval+1) WHERE seq_name='C';
END IF

SELECT seq_currval INTO result 
FROM id_generator 
WHERE seq_name = delimeter;

RETURN result;
END $$

DELIMITER ;

I'm trying to create a MySQL function, but I get the following error:

código de error: 1064
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 'SELECT seq_currval INTO result
from id_generator
WHERE seq_name = delimeter;
R' at line 9

¿Cuál es el problema?

preguntado el 04 de septiembre de 13 a las 02:09

Problema #1: No demonstration of any troubleshooting. Problema #2: Did not bother to use formatting for code when asking question. Problema #3: Did not read the ayuda page for an introduction to StackOverflow. Problema #4: Is this really MySQL, or some other SQL that you're trying to copy-paste as a MySQL query? Problema #5: Do you understand what the query is trying to do? What are you trying to achieve (specifically, HOW are you trying to achieve it; remember, people charge hourly rates for coding, so don't make this a chore/job). Mi respuesta: Syntax error. -

Maybe you are just missing a semi-colon after the END IF...and therefore mysql doesn't understand the next statement (SELECT seq_...) -

add semi-colon,but get the error ... 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 13 -

2 Respuestas

Cambiar ELSE IF a ELSEIF En todas partes,

Respondido el 04 de Septiembre de 13 a las 02:09

oh...!! thank you!!! solve problem~ - Ho Ho Ho

and i will try to use this function SELECT ecmsbackoffice.getSequence('D'); but i get error :( error code: 1054 Unknown column 'delimeter' in 'field list' one more please ... - Ho Ho Ho

Intenta eliminar $ aquí: delimeter VARCHAR(20) - Alex

@민종현 Please accept an answer if it helped you. - Alex

Tienes tres abiertos if statements and only one end if. Hay una diferencia entre else if y elseif (note the space). Try this:

IF (delimeter='B') THEN UPDATE id_generator SET seq_currval=(seq_currval+1) WHERE seq_name='B';
ELSEIF (delimeter='D') THEN UPDATE id_generator SET seq_currval=(seq_currval+1) WHERE seq_name='D';
ELSEIF (delimeter='C') THEN UPDATE id_generator SET seq_currval=(seq_currval+1) WHERE seq_name='C';
END IF;

Also, just for reference, the proper spelling is probably "delimiter" and not "delimeter".

Respondido el 04 de Septiembre de 13 a las 02:09

and i will try to use this function SELECT ecmsbackoffice.getSequence('D'); but i get error :( error code: 1054 Unknown column 'delimeter' in 'field list' one more please ... - Ho Ho Ho

No necesitas el '$' in front of the parameter name. - gordon linoff

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.