MySQL如何从[存储过程]插入[临时表] [英] MySQL How to INSERT INTO [temp table] FROM [Stored Procedure]

查看:276
本文介绍了MySQL如何从[存储过程]插入[临时表]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这与问题 653714 非常相似,但适用于MySQL而不是SQL Server.

This is very similar to question 653714, but for MySQL instead of SQL Server.

基本上,我有一个复杂的选择,它是几个存储过程的基础.我想在存储过程中共享代码,但是,我不确定如何执行此操作.我可以执行此操作的一种方法是,使共享选择存储过程,然后从其他存储过程中调用该存储过程.我不知道如何使用嵌套存储过程的结果集.如果我可以将它们放在临时表中,则可以有效地使用结果,但是我不知道如何将它们放入临时表中.例如,这不起作用:

Basically, I have a complicated select that is the basis for several stored procedures. I would like to share the code across the stored procedures, however, I'm not sure how to do this. One way I could do this is by making the shared select a stored procedure and then calling that stored procedure from the other ones. I can't figure out how to work with the result set of the nested stored procedure. If I could put them in a temp table I could use the results effectively, but I can't figure out how to get them in a temp table. For example, this does not work:

CREATE TEMPORARY TABLE tmp EXEC nested_sp();

推荐答案

问题是,存储过程实际上并不直接返回输出.他们可以在脚本内执行select语句,但是没有返回值.

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通过CALL StoredProcedureName();调用存储过程,您不能将输出定向到任何东西,因为它们不返回任何东西(不同于函数).

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调用命令

这篇关于MySQL如何从[存储过程]插入[临时表]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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