MySQL How to INSERT INTO [temp table] FROM [Stored Procedure] MySQL How to INSERT INTO [temp table] FROM [Stored Procedure] sql sql

MySQL How to INSERT INTO [temp table] FROM [Stored Procedure]


The problem is, Stored Procedures don't really return output directly. They can execute select statements inside the script, but have no return value.

MySQL calls stored procedures via CALL StoredProcedureName(); And you cannot direct that output to anything, as they don't return anything (unlike a function).

MySQL Call Command


My first reaction was "That sounds like a view to me". Doesn't that abstract it enough so you can just add the variability into an SP per case?

Anything that adds a temp table that wouldn't otherwise be there is a very likely antipattern.


You cannot "SELECT INTO" with stored procedures.

Create the temporary table first and have your stored procedure to store the query result into the created temporary table using normal "INSERT INTO". The temporary table is visible as long as you drop it or until the connection is closed.