ja_him
ja_him

Reputation: 447

MySQL END LOOP error

I've been reading up a lot, but everything I've read on name_of_loop: LOOP ... END LOOP name_of_loop; seems to suggest that what I'm doing is correct. Where am I going wrong? I think I'm using the correct syntax for the variables because it's a stored procedure (I think...), I'm delimiting on a character other than ; for the stored procedure. From what I've read I'm also doing the comparison correctly...

I get the following error:

#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 

From the following:

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();

Upvotes: 0

Views: 875

Answers (1)

PravinS
PravinS

Reputation: 2584

you have missed END IF;

hope this will work

Upvotes: 1

Related Questions