MySQL - syntaxis error

 
Vista:
Imágen de perfil de Monsse

syntaxis error

Publicado por Monsse (1 intervención) el 25/09/2013 18:08:52
Estoy creando este procedimiento y necesito 3 cursores apenas abri el primero y ya tengo error , al declarar la variable del cursor, si quito esa linea me lo pone al declarar el cursor , me pueden ayudar porfas

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
DELIMITER //
 
CREATE PROCEDURE bookup.subscriptions_sp (fecha_repartir date)
 
BEGIN
		CREATE TEMPORARY TABLE IF NOT EXISTS bookup.tmp_subscriptions
		(	Ruta INT(11) NOT NULL,
			Repartidor INT(11) NOT NULL,
			Publicacion INT(11) NOT NUll,
			Tipo_Suscripcion INT(11) NOT NULL,
			Tipo_Aviso INT(11) NOT NULL,
			Vigentes_Pagadas DECIMAL(15,2) NOT NULL DEFAULT 0,
			Vigentes_Cortesia DECIMAL(15,2) NOT NULL DEFAULT 0,
			Altas DECIMAL(15,2) NOT NULL DEFAULT 0,
			Bajas DECIMAL(15,2) NOT NULL DEFAULT 0,
			Vigentes_Pagadas_Ant DECIMAL(15,2) NOT NULL DEFAULT 0,
			Vigentes_Cortesia_Ant DECIMAL(15,2) NOT NULL DEFAULT 0
		);
 
	declare repartidor_id int(11); ##Aqui me marca error syntax unexpected declare_sym
 
	DECLARE repartidor CURSOR FOR
		SELECT id from bookup.people where is_delivery= 1;
 
	OPEN repartidor;
 
	FETCH repartidor INTO repartidor_id;
 
	CLOSE repartidor;
 
END
 
//
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Willian
Val: 2
Ha aumentado su posición en 60 puestos en MySQL (en relación al último mes)
Gráfica de MySQL

syntaxis error

Publicado por Willian (52 intervenciones) el 02/10/2013 22:41:49
Hola Monsse tu problema es bien simples tienes crear tu tabla despues de todos los cursores declarados...
mysql no permiter hacer declaraciones explicitas tables como crear, dropear, selects, updates, etc antes de declarar todos los cursores que vas a necesitar entonces en tu caso quedaria asi

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
DELIMITER //
 
CREATE PROCEDURE bookup.subscriptions_sp (fecha_repartir date)
 
BEGIN
 
 
	declare repartidor_id int(11); ##Aqui me marca error syntax unexpected declare_sym
 
	DECLARE repartidor CURSOR FOR
		SELECT id from bookup.people where is_delivery= 1;
	CREATE TEMPORARY TABLE IF NOT EXISTS bookup.tmp_subscriptions
		(	Ruta INT(11) NOT NULL,
			Repartidor INT(11) NOT NULL,
			Publicacion INT(11) NOT NUll,
			Tipo_Suscripcion INT(11) NOT NULL,
			Tipo_Aviso INT(11) NOT NULL,
			Vigentes_Pagadas DECIMAL(15,2) NOT NULL DEFAULT 0,
			Vigentes_Cortesia DECIMAL(15,2) NOT NULL DEFAULT 0,
			Altas DECIMAL(15,2) NOT NULL DEFAULT 0,
			Bajas DECIMAL(15,2) NOT NULL DEFAULT 0,
			Vigentes_Pagadas_Ant DECIMAL(15,2) NOT NULL DEFAULT 0,
			Vigentes_Cortesia_Ant DECIMAL(15,2) NOT NULL DEFAULT 0
		);
	OPEN repartidor;
 
	FETCH repartidor INTO repartidor_id;
 
	CLOSE repartidor;
 
END


saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar