I have two tables:
people_en: id, name people_es: id, name
(please don’t worry about normalization, the design is normalized. The tables are much more complicated than that, but this is just a way to simplify my problem).
Then I have a stored procedure:
CREATE PROCEDURE myproc(lang char(2)) BEGIN set @select = concat('SELECT * FROM ', lang, ' limit 3'); PREPARE stm FROM @select; EXECUTE stm; DEALLOCATE PREPARE stm; SET @cnt = FOUND_ROWS(); SELECT @cnt; IF @cnt = 3 THEN //Here I need to loop through the rows ELSE //Do something else END IF; END$$
More or less, the logic in the procedure:
If the choice gives 3 lines, we have to go through the lines and do something with the value in each line. Otherwise, something else (it doesn’t matter what, but I put this so that you understand that I need to have an if statement before the loop.
I saw and read about cursors, but couldn't find much for the favorites created by concat (does that matter?) And especially created with a prepared expression. How can I iterate over a list of results and use the values from each row? Thanks.
source share