mysql - 我的带有游标的存储过程没有运行

标签 mysql stored-procedures

这是我的查询。我正在按照所有步骤创建带有游标的过程,但不起作用

    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

enter image description here

我的错误是什么?请

最佳答案

您似乎缺少分隔符

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/

相关文章:

python - 如何在 Python 中从 Azure Function 调用 Cosmos DB 存储过程?

php - MySQL Where 子句中的数组

sql - 如何从 Crystal Reports 调用存储过程?

返回更新记录的 SQL Server 存储过程

涉及聚合数据的 MySQL 连接

c# - 存储过程返回错误的小数点

sql - 消除并减少重叠的日期范围

mysql - 在mysql中创建 View 时可以将单元格设置为数组吗

php - 将天数添加到显示奇数的时间戳

MySQL,什么是SQL接口(interface)?