MySQL procedure's cursor stops after first iteration
Before MySQL 5.6, stored procedures had only one handler, see the changelogs for 5.6:
In addition, several deficiencies in condition handler processing rules were corrected so that MySQL behavior is more like standard SQL:
- Block scope is used in determining which handler to select. Previously, a stored program was treated as having a single scope for handler selection.
So your NOT FOUND
continue handler will unfortunately be triggered by not finding rows in mapping_civility
in your function, because you used into
there.
You can reinitialize the variable directly before you fetch new rows to reset everything that has happend before:
...
LOOP1: LOOP
set no_more_rows1 = false; -- add this
FETCH curseur1 INTO my_name;
IF no_more_rows1 THEN
...
If you have nested loops like in your original question, be aware that it will still only be one (active) handler, so use the same variable for both loops and reset it before each fetch
.
For MySQL 5.6 and up, your current code would work as expected.