这是我的查询。我正在按照所有步骤创建带有游标的过程,但不起作用
CREATE PROCEDURE `sp_prueba1` (
codigo1 int,
estado1 int,
llave_maestra1 char(10),
fecha_actual1 date,
rango_inicial1 varchar(20),
rango_final1 varchar(20))
BEGIN
DECLARE est1 int;
DECLARE conteo1 int;
/*Abro cursor*/
DECLARE cur1 CURSOR FOR SELECT Oel_Estado FROM Operaciones_Especiales_Llave WHERE Em_Codigo=codigo1;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN cur1;
/*INICIO LOOP*/
read_loop: LOOP
FETCH cur1 INTO est1;
IF done THEN
LEAVE read_loop;
ELSE
SELECT conteo1,finicio1,ffin1,cod1,est1;
END IF;
END LOOP;
/*FIN LOOP*/
CLOSE cur1;
/*CIERRO CURSOR*/
END
我的错误是什么?请
最佳答案
您似乎缺少分隔符
。
If you use the mysql client program to define a stored program containing semicolon characters, a problem arises. By default, mysql itself recognizes the semicolon as a statement delimiter, so you must redefine the delimiter temporarily to cause mysql to pass the entire stored program definition to the server. To redefine the mysql delimiter, use the delimiter command.
Delimiter //
CREATE PROCEDURE `sp_prueba1` (
codigo1 int,
estado1 int,
llave_maestra1 char(10),
fecha_actual1 date,
rango_inicial1 varchar(20),
rango_final1 varchar(20))
BEGIN
DECLARE est1 int;
DECLARE conteo1 int;
/*Abro cursor*/
DECLARE cur1 CURSOR FOR SELECT Oel_Estado FROM Operaciones_Especiales_Llave WHERE Em_Codigo=codigo1;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN cur1;
/*INICIO LOOP*/
read_loop: LOOP
FETCH cur1 INTO est1;
IF done THEN
LEAVE read_loop;
ELSE
SELECT conteo1,finicio1,ffin1,cod1,est1;
END IF;
END LOOP;
/*FIN LOOP*/
CLOSE cur1;
/*CIERRO CURSOR*/
END
Delimiter;
以后请引用Dev.mysql .
关于mysql - 我的带有游标的存储过程没有运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32939857/