MySQL END LOOP错误

时间:2015-08-13 11:30:46

标签: mysql sql

我已经阅读了很多内容,但我在name_of_loop: LOOP ... END LOOP name_of_loop;上阅读的所有内容似乎都表明我所做的是正确的。我哪里错了?我认为我使用了正确的变量语法,因为它是一个存储过程(我认为......),我对存储过程的;以外的字符进行了分界。根据我的阅读,我也正确地进行了比较...

我收到以下错误:

#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 'LOOP get_revision_id;

CLOSE cursor_1;

END' at line 25 

以下内容:

DELIMITER $$

DROP PROCEDURE IF EXISTS update_revision_ids $$

CREATE PROCEDURE update_revision_ids ()

BEGIN
DECLARE finished INTEGER DEFAULT 0;
DECLARE sub_id INTEGER;
DECLARE rev_id INTEGER;
DECLARE cursor_1 CURSOR FOR SELECT sid FROM subscription;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET finished = 1;
OPEN cursor_1;

    get_revision_id: LOOP

        FETCH cursor_1 INTO sub_id;
        IF finished = 1 THEN LEAVE get_revision_id;

        SELECT revision_id
        INTO rev_id
        FROM subscription_revision 
        WHERE subscription_revision.sid = sub_id;

        UPDATE subscription
        SET subscription.revision_id = rev_id
        WHERE subscription.sid = sub_id;

    END LOOP get_revision_id;

CLOSE cursor_1;

END $$

DELIMITER ;

CALL update_revision_ids();

1 个答案:

答案 0 :(得分:1)

你错过了END IF;

希望这会有用