如何在mysql中使用select语句调用存储过程 [英] How to call a stored procedure using select statement in mysql

查看:1158
本文介绍了如何在mysql中使用select语句调用存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似

 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'));

但是发生错误. 像

错误代码:1064.您的SQL语法有错误;检查 与您的MySQL服务器版本相对应的手册 在((CALL report_procedure ('2013-02-01',now(),'2015-01-01','1')在第3行0.297秒

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

有人可以建议我在mysql的Select语句中调用存储过程的方法吗?

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

推荐答案

无法在FROM子句中使用过程中的结果集. MySQL不允许这样做.

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

您可以在过程中填充另一个表(或临时表),然后在SELECT命令中使用该表-

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;

这篇关于如何在mysql中使用select语句调用存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆