PDA

Ver la Versión Completa : Problema con este function en mysql


teecweb
29-03-2013, 00:19:08
Tengo una consulta que al ejecutra en el servidor me ocurre este error
me sale el error de mysql 1024..lo que me parece ma extraño al ejecutar localmente me ejecuta normalmente ..gracias por tu respuesta :D


CREATE DEFINER=`root`@`localhost` FUNCTION `RomanToInteger`(
`xstrRoman` varchar(4)
) RETURNS int(11)
BEGIN
DECLARE xi INT;
DECLARE xstrCharacther CHAR(30);
DECLARE xintResult INT;
DECLARE xintNewValue INT;
DECLARE xintOldValue INT;

SET xstrRoman = UPPER(xstrRoman);
SET xintOldValue = 1000;
SET xintNewValue = 0;
SET xintResult = 0;
SET xi=1;

WHILE (xi<= length(xstrRoman)) DO
SET xstrCharacther = SUBSTRING(xstrRoman, xi, 1);

CASE xstrCharacther
WHEN 'I' THEN SET xintNewValue = 1;
WHEN 'V' THEN SET xintNewValue = 5;
WHEN 'X' THEN SET xintNewValue = 10;
WHEN 'L' THEN SET xintNewValue = 50;
WHEN 'C' THEN SET xintNewValue = 100;
WHEN 'D' THEN SET xintNewValue = 500;
WHEN 'M' THEN SET xintNewValue = 1000;
END CASE;

IF xintNewValue > xintOldValue THEN
SET xintResult = xintResult + xintNewValue - 2 * xintOldValue;
ELSE
SET xintResult = xintResult + xintNewValue;
END IF;
SET xintOldValue = xintNewValue;
SET xi=xi+1;

END WHILE;
Return xintResult;
END

teecweb
29-03-2013, 00:50:24
Holas.. eh ejecutado una consulta en mysql remotamente y me bota el error 1024 pero al ejecutar localmente me corre normalmente le envio el codigo original..abajo le envio un zip mostrando la imagen..gracias por sus respuestas:D




DELIMITER $$
CREATE DEFINER=`usermysql`@`localhost` FUNCTION `RomanToInteger`(
`xstrRoman` varchar(4)
) RETURNS int(11)
BEGIN
DECLARE xi INT;
DECLARE xstrCharacther CHAR(30);
DECLARE xintResult INT;
DECLARE xintNewValue INT;
DECLARE xintOldValue INT;

SET xstrRoman = UPPER(xstrRoman);
SET xintOldValue = 1000;
SET xintNewValue = 0;
SET xintResult = 0;
SET xi=1;

WHILE (xi<= length(xstrRoman)) DO
SET xstrCharacther = SUBSTRING(xstrRoman, xi, 1);

CASE xstrCharacther
WHEN 'I' THEN SET xintNewValue = 1;
WHEN 'V' THEN SET xintNewValue = 5;
WHEN 'X' THEN SET xintNewValue = 10;
WHEN 'L' THEN SET xintNewValue = 50;
WHEN 'C' THEN SET xintNewValue = 100;
WHEN 'D' THEN SET xintNewValue = 500;
WHEN 'M' THEN SET xintNewValue = 1000;
END CASE;

IF xintNewValue > xintOldValue THEN
SET xintResult = xintResult + xintNewValue - 2 * xintOldValue;
ELSE
SET xintResult = xintResult + xintNewValue;
END IF;
SET xintOldValue = xintNewValue;
SET xi=xi+1;

END WHILE;
Return xintResult;
END

Casimiro Notevi
29-03-2013, 00:56:52
Por favor, deja de repetir hilos, gracias.

Casimiro Notevi
29-03-2013, 01:00:08
Puedes copiar el mensaje y te ahorras de estar pegando imágenes:

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

teecweb
29-03-2013, 01:01:18
Disculpe pero no estoy repitiendo hilos..solo es una nueva pregunta..gracias

Casimiro Notevi
29-03-2013, 01:03:46
Disculpe pero no estoy repitiendo hilos..solo es una nueva pregunta..gracias

Estás repìtiendo hilos. ¿Acaso no son iguales los 2 mensajes de arriba?, estaban en hilos distintos, en foros distintos, y los he unidos.

teecweb
29-03-2013, 01:07:52
No me habia fijado solo que primera vez que quize enviar el primer mensaje y quize editar me salio que ya no podia editar y no salio el mensaje y por eso lo hize otra vez ..y lo mande..mi intencion no era enredar con muchos hilos ..solo mandar mi pregunta y respetar las reglas del foro..igualmente gracias..:D

Casimiro Notevi
29-03-2013, 01:14:20
No hay problema, en todo caso para otra vez, puedes pedir a cualquier moderador que te lo edite. Gracias :)

Casimiro Notevi
29-03-2013, 01:16:54
Creo que el error lo tienes aquí:
end if; /* ¿ sobra el if ? */
Supongo que será sólo end, sin el if, eso es de basic.

teecweb
29-03-2013, 01:21:50
No creo cuando lo quito me sale error de sintaxis..

Casimiro Notevi
29-03-2013, 01:31:50
No creo cuando lo quito me sale error de sintaxis..
Y si lo dejas, también :p:D

teecweb
29-03-2013, 01:34:08
El error es por por el case..no por el if segun veo la imagen que envie..el en if si lo kito me sale error y sino esta bien ,,gracias :)

Casimiro Notevi
29-03-2013, 01:58:47
¿Has visto algún tutorial mysql?, ahí puedes confirmar cómo es la sintaxis.
Te pego tu imagen.

http://farm9.staticflickr.com/8521/8598315963_693c2c4746_b.jpg

teecweb
29-03-2013, 03:55:05
aqui le envio el pantallazo de la sintaxis..gracias

2609

2610

Casimiro Notevi
29-03-2013, 11:37:39
En lugar de pegar imágenes que no sirven de mucho, haz un copia pega del código y usa las etiquetas.
Recuerda poner los tags al código fuente, ejemplo:

http://www.clubdelphi.com/images/UtilizarTAGs.png

Gracias :)