MySQL 游标中的循环语法错误
Loop syntax error in MySQL 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
我在这里错过了什么?
您不能提取到用户定义的变量中。这是一个存在多年的错误,请参阅 https://bugs.mysql.com/bug.php?id=2261
为其声明一个常规局部变量。
我一直在尝试使用游标,并且按照我在网上找到的教程,我能够想出以下游标。
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
我在这里错过了什么?
您不能提取到用户定义的变量中。这是一个存在多年的错误,请参阅 https://bugs.mysql.com/bug.php?id=2261
为其声明一个常规局部变量。