Let's say we have a stored procedure selecting something from a table:
CREATE PROCEDURE database.getExamples() SELECT * FROM examples;
How can I use the result from this procedure in a later select? (I've tried
SELECT * FROM (CALL database.getExamples())
but with no success.) Should I use SELECT... INTO outVariable in the procedure? Or should I use a function returning the table instead?
Create a simple stored procedure. DELIMITER ; To create the MySQL Stored Procedure, open the MySQL workbench Connect to the MySQL Database copy-paste the code in the query editor window click on Execute. You can view the procedure under stored procedures.
This procedure accepts id of the customer as IN parameter and returns product name (String), customer name (String) and, price (int) values as OUT parameters from the sales table. To call the procedure with parameters pass @parameter_name as parameters, in these parameters the output values are stored.
We can not directly use stored procedures in a SELECT statement.
Expand Stored Procedures, right-click the procedure and then select Script Stored Procedure as, and then select one of the following: Create To, Alter To, or Drop and Create To. Select New Query Editor Window. This will display the procedure definition.
Reformulated the question in this thread: Can a stored procedure/function return a table?. Obviously, it isn't possible without the use for temp tables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With