Skip to content
Advertisement

How to return multiple rows in stored procedure?

I have a procedure that returns multiple rows, but separately. Please take a look at its result:

enter image description here

I causes some issues when I want to fetch the result in the code (backend side). Now I want to create a temporary table and insert all rows inside it and then return that temp table as the result of the stored procedure. How can I do that inside procedure?

Not sure it above idea is a good idea .. that’s the only thing I can probably be useful to merge all rows all in one table as SP’s result.

Here is my current procedure:

Noted that, the MySQL version I use is MySQL v8.0.20.

Advertisement

Answer

The logic should be something like this. Outside the loop create a temp table if not exists and delete the data from it:

In your loop:

After your loop:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement