MySQL游标中的循环语法错误

时间:2016-08-22 02:20:57

标签: mysql loops cursor

我一直在尝试使用光标并按照我在网上找到的教程,我能够提出以下光标。

DELIMITER $$

CREATE PROCEDURE customers_with_oldest_version (INOUT customerCount varchar(4000))
BEGIN

DEClARE customers_with_oldest_version CURSOR FOR
select * from CustomerSoftware where software in (select min(minimumSoftware) from ProductSoftware);

DECLARE CONTINUE HANDLER 
FOR NOT FOUND SET @finished = 1;

set @row_entry = "";

open customers_with_oldest_version;

get_customers: LOOP

FETCH customers_with_oldest_version INTO @row_entry;

IF @finished = 1 THEN 
 LEAVE get_customers;
 END IF;

SET @customerCount = @customerCount + 1;

END LOOP;

CLOSE customers_with_oldest_version;

END$$

DELIMITER ;

但我无法创建此过程,因为phpmyadmin给出了一个错误说明 #1064 - 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 '@row_entry; IF @finished = 1 THEN LEAVE get_customers; END IF; SET @c' at line 16

我在这里缺少什么?

1 个答案:

答案 0 :(得分:0)

您无法获取用户定义的变量。这是一个已存在多年的错误,请参阅https://bugs.mysql.com/bug.php?id=2261

为它声明一个常规的局部变量。