Running this routine on HeidiSQL and it runs with 0 rows affected, even though there should be exactly 1 row affected. both select statements seem to work fine outside this Stored Procedure.
BEGIN
DECLARE someId INT;
DECLARE done INT DEFAULT FALSE;
DECLARE cur1 CURSOR FOR
select anotherId from tableA
where yetAnotherId IN(another select statement);
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN cur1;
read_loop: LOOP
IF done THEN
LEAVE read_loop;
END IF;
FETCH cur1 INTO someId;
update tableB
set x = 'hello', y = 'world'
where something = someId;
END LOOP;
CLOSE cur1;
END;
I would like to get an idea what could be wrong with the structure of this routine. It looks to me that even thoughthe cursor should contain 1 entry, It does not.
Thanks
EDIT: It looks like 'someId' was matching a table field with the same name, thus the issue. This has been resolved now.