【问题标题】:Loop syntax error in MySQL cursorMySQL游标中的循环语法错误
【发布时间】:2016-08-22 02:20:56
【问题描述】:

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

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

我在这里错过了什么?

【问题讨论】:

  • 你从不使用@row_entry。你为什么要进去?
  • @Barmar 我打算稍后使用它。我只是想看看是什么导致了这个错误。

标签: mysql loops cursor


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2018-05-20
    • 2013-09-28
    • 1970-01-01
    • 2020-08-02
    • 2012-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多