Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySql stored procedures: How to select from procedure table?

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?

like image 219
Cambiata Avatar asked Oct 27 '09 07:10

Cambiata


People also ask

How do I SELECT a stored procedure in MySQL?

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.

How do I call a procedure with parameters in MySQL?

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.

Can we use SELECT in stored procedure?

We can not directly use stored procedures in a SELECT statement.

How do I SELECT a stored procedure in SQL?

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.


1 Answers

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.

like image 58
Cambiata Avatar answered Oct 03 '22 03:10

Cambiata