Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » Mysql »

[SOLUCIONADO] Error creando Stored Procedure

Estas en el tema de Error creando Stored Procedure en el foro de Mysql en Foros del Web. Hola gente del foro, estoy tratando de crear un Stored Procedure que me pasaron para implementar en pre-producción, utilizo Workbench pero me arroja error, alguien ...
  #1 (permalink)  
Antiguo 11/03/2015, 07:46
 
Fecha de Ingreso: octubre-2014
Ubicación: Buenos Aires
Mensajes: 278
Antigüedad: 9 años, 6 meses
Puntos: 12
Error creando Stored Procedure

Hola gente del foro, estoy tratando de crear un Stored Procedure que me pasaron para implementar en pre-producción, utilizo Workbench pero me arroja error, alguien me podría indicar donde puede estar el error.

Versión de MySql 5.6

Stored Procedure

Código MySQL:
Ver original
  1. CREATE PROCEDURE `limite_dnr_nuevo` (IN tu INT, OUT nuevodr INT)
  2. DECLARE incrementa INT;
  3. DECLARE lastdr INT;
  4. DECLARE toplimit INT;
  5. SELECT tope INTO top FROM devriver_dnr where id = tu;
  6. SELECT dnr INTO dr FROM devriver_dnr where id = tu;
  7. SET lastdr = (select dr) ;
  8. SET toplimit = (select top);
  9. IF tu = 1 THEN
  10.     IF lastdr > toplimit THEN  
  11.         SELECT dnr INTO dr FROM devriver_dnr where id = 2;
  12.         SET lastdr = (select dr) ;
  13.        
  14.         SET incrementa = lastdr + 1;
  15.         UPDATE devriver_dnr SET dnr = incrementa WHERE id = 2;
  16.         SELECT incrementa;
  17.     else
  18.         SELECT dnr INTO dr FROM devriver_dnr where id = tu;
  19.         SET lastdr = (select dr) ;
  20.         SET incrementa = lastdr + 1;
  21.         UPDATE devriver_dnr SET dnr = incrementa WHERE id = tu;
  22.         SELECT incrementa;
  23.     END IF;
  24.         SELECT dnr INTO dr FROM devriver_dnr where id = tu;
  25.         SET lastdr = (select dr) ;
  26.         SET incrementa = lastdr + 1;
  27.         UPDATE devriver_dnr SET dnr = incrementa WHERE id = tu;
  28.         SELECT incrementa;
  29.  
  30. SET nuevodr = incrementa;

Error que devuelve

mysql> use vamosriver
No connection. Trying to reconnect...
Connection id: 593723
Current database: *** NONE ***

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> \. /home/mysql/Descargas/procedureDR.sql
ERROR 1064 (42000): 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 5
ERROR 1064 (42000): 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 'DECLARE dr INT' at line 1
ERROR 1064 (42000): 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 'DECLARE incrementa INT' at line 1
ERROR 1064 (42000): 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 'DECLARE lastdr INT' at line 1
ERROR 1064 (42000): 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 'DECLARE toplimit INT' at line 1
ERROR 1327 (42000): Undeclared variable: top
ERROR 1327 (42000): Undeclared variable: dr
ERROR 1193 (HY000): Unknown system variable 'lastdr'
ERROR 1193 (HY000): Unknown system variable 'toplimit'
ERROR 1064 (42000): 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 'IF tu = 1 THEN
IF lastdr > toplimit THEN
SELECT dnr INTO dr FROM devriver_dn' at line 1
ERROR 1193 (HY000): Unknown system variable 'lastdr'
ERROR 1193 (HY000): Unknown system variable 'incrementa'
ERROR 1054 (42S22): Unknown column 'incrementa' in 'field list'
ERROR 1054 (42S22): Unknown column 'incrementa' in 'field list'
ERROR 1064 (42000): 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 'else
SELECT dnr INTO dr FROM devriver_dnr where id = tu' at line 1
ERROR 1193 (HY000): Unknown system variable 'lastdr'
ERROR 1193 (HY000): Unknown system variable 'incrementa'
ERROR 1054 (42S22): Unknown column 'tu' in 'where clause'
ERROR 1054 (42S22): Unknown column 'incrementa' in 'field list'
ERROR 1064 (42000): 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 'END IF' at line 1
ERROR 1064 (42000): 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 'else
SELECT dnr INTO dr FROM devriver_dnr where id = tu' at line 1
ERROR 1193 (HY000): Unknown system variable 'lastdr'
ERROR 1193 (HY000): Unknown system variable 'incrementa'
ERROR 1054 (42S22): Unknown column 'tu' in 'where clause'
ERROR 1054 (42S22): Unknown column 'incrementa' in 'field list'
ERROR 1064 (42000): 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 'END IF' at line 1
ERROR 1193 (HY000): Unknown system variable 'nuevodr'
ERROR 1064 (42000): 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 'END' at line 1
mysql> \t


Desde ya agradezco su ayuda.
__________________
http://www.sp-vision.net
  #2 (permalink)  
Antiguo 11/03/2015, 11:31
 
Fecha de Ingreso: octubre-2014
Ubicación: Buenos Aires
Mensajes: 278
Antigüedad: 9 años, 6 meses
Puntos: 12
Respuesta: Error creando Stored Procedure

Le estaba faltando los DELIMITER. Habia leido que los DELIMITER solo se utilizaban en la consola.

Saludos.
__________________
http://www.sp-vision.net
  #3 (permalink)  
Antiguo 11/03/2015, 11:34
Avatar de gnzsoloyo
Moderador criollo
 
Fecha de Ingreso: noviembre-2007
Ubicación: Actualmente en Buenos Aires (el enemigo ancestral)
Mensajes: 23.324
Antigüedad: 16 años, 5 meses
Puntos: 2658
Respuesta: Error creando Stored Procedure

Nop. También si lo cargas por script...
__________________
¿A quién le enseñan sus aciertos?, si yo aprendo de mis errores constantemente...
"El problema es la interfase silla-teclado." (Gillermo Luque)

Etiquetas: procedure, stored
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:11.