使用MySql 5.7的While-Loop我的错在哪里?

问题描述

我在这里的第一个问题,所以是“ Hello world”;)希望有一天我能提供一些帮助。 这是我的问题,首先是我的SQL查询:
我是否需要将此While循环放入过程中?实际上,我想构建一个嵌套循环(实际上是for-循环)。 SQL中的这种技术对我来说是新的。所以我想首先尝试一个像上面这样的小例子。但是经过一些更改之后,出现了更多的故障:)。我试图按照手册中的信息进行操作,但是没有机会。 我的错在哪里?

CREATE PROCEDURE dowhile()
    BEGIN
        DECLARE j INT DEFAULT 1;
        DECLARE j_total INT DEFAULT 10;


    WHILE j < j_total DO
        SELECT TOP 1 * FROM `collection_dates` WHERE `ortsnummer` = j AND `pid` = '1' ORDER 
        BY `termin_date` ASC;
        SET j = j + 1;
    END WHILE;
END

CALL dowhile();

错误:

[FEHLER in Abfrage 1] 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 '' at line 3
[FEHLER in Abfrage 2] 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 'DECLARE j_total INT DEFAULT 10' at line 1
[FEHLER in Abfrage 3] 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 'WHILE j < j_total DO
            SELECT TOP 1 * FROM `collection_dates` WHERE `ortsnummer' at line 1
[FEHLER in Abfrage 4] Unknown system variable 'j'

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)