Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a stored procedure using select statement in mysql

I have call statement like

 CALL report_procedure
('2013-02-01',now(),'2015-01-01','1');

and i want to use it in a select query. i have tried like

Select * from ( CALL report_procedure
    ('2013-02-01',now(),'2015-01-01','1'));

but error occurs. like

Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ( CALL report_procedure ('2013-02-01',now(),'2015-01-01','1') at line 3 0.297 sec

Can anyone suggest me a method to call stored procedure in Select statement in mysql??

like image 791
vineeth Avatar asked Aug 20 '15 12:08

vineeth


1 Answers

It is not possible to use result set from procedure in FROM clause. MySQL does not allow doing this.

You may populate another table (or temporary table) in your procedure, and after, use that table in SELECT commands -

CALL report_procedure ('2013-02-01',now(),'2015-01-01','1'); -- fill temp_table
SELECT * FROM temp_table;
like image 147
Devart Avatar answered Oct 14 '22 01:10

Devart