在 MySQL 中的存储过程中调用存储过程 [英] Calling a Stored Procedure in a Stored Procedure in MySQL

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

问题描述

我在任何地方都找不到这个答案,但是您可以从 MySQL 中的另一个存储过程调用存储过程吗?我想取回标识值并在父存储过程中使用它.我们不能再使用 FUNCTIONS!

I can't find this answer anywhere, but can you call a Stored Procedure from another Stored Procedure in MySQL? I want to get the Identity Value back and use it in the parent Stored Procedure. We can't use FUNCTIONS anymore!

推荐答案

CREATE PROCEDURE innerproc(OUT param1 INT)
BEGIN
 insert into sometable;
 SELECT LAST_INSERT_ID() into param1 ;
END
-----------------------------------
CREATE PROCEDURE outerproc()
BEGIN
CALL innerproc(@a);
// @a gives you the result of innerproc
SELECT @a INTO variableinouterproc FROM dual;
END

OUT 参数应该可以帮助您将值返回给调用过程.基于此,解决方案必须是这样的.

OUT parameters should help you in getting the values back to the calling procedure.Based on that the solution must be something like this.

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

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