0
DECLARE oldID int;
DECLARE DONE boolean DEFAULT FALSE;
DECLARE fineCursor CURSOR FOR SELECT `ifLinkID` FROM `image_fine_link` WHERE `image_id` = pimage_id;
DECLARE coarseCursor CURSOR FOR SELECT `icLinkID` FROM `image_coarse_link` WHERE `image_id` = pimage_id;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET DONE = TRUE;


OPEN fineCursor;
OPEN coarseCursor;

read_loop : LOOP
    oldID = NULL;
    FETCH fineCursor INTO oldID;
    IF oldID IS NOT NULL THEN
    CALL update_others(oldID,"delete","fine color",NULL);
    END IF;

    IF !DONE THEN ITERATE read_loop;
    END IF;
    LEAVE read_loop;
END LOOP;

SET DONE = FALSE;

read_lopp : LOOP
    oldID = NULL;
    FETCH coarseCursor INTO oldID;
    IF oldID IS NOT NULL THEN
    CALL update_others(oldID,"delete","coarse color",NULL);
    END IF;

    IF !DONE THEN ITERATE read_loop; 
    END IF;
    LEAVE read_loop;
END LOOP;

CLOSE fineCursor;
CLOSE coarseCursor;

And the following error appears, really emergent, any idea ?

#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 '= NULL;
    FETCH fineCursor INTO oldID;
    IF oldID IS NOT NULL THEN
    CALL upd' at line 16 

Thank you so much sincerely !~

1 Answer 1

1

That particular error is caused by fact that you didn't use SET statement to assign a value to a variable.

Change

oldID = NULL;

to

SET oldID = NULL;
Sign up to request clarification or add additional context in comments.

4 Comments

@user2741837 You're welcome :) If it was what you were looking for please, consider to accept the answer.
Hi indeed there is another problem with this code: the error reports: #1308 - ITERATE with no matching label: read_loop, I guess it's because the scope of label is not visible to the loop, what am I supposed to do instead, as I always need a judgement condition to leave or iterate the loop ? :) Appreciate it if you can help
You have a typo read_lopp : LOOP. lopp instead of loop. BTW you should use two different labels e.g. (read_loop and read_loop2)
Thanks so much, I'm quite a newbie in stackoverflow. This is the first question I posted :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.