Ver Mensaje Individual
  #1 (permalink)  
Antiguo 11/03/2015, 07:46
mauritosuarez
 
Fecha de Ingreso: octubre-2014
Ubicación: Buenos Aires
Mensajes: 278
Antigüedad: 9 años, 7 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