OUT或INOUT参数不起作用 [英] OUT or INOUT parameter not working

查看:365
本文介绍了OUT或INOUT参数不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在MySQL中使用OUT或INOUT参数创建存储过程,它将无法正常工作.即使我将存储过程留空. DDL如下:

If I create a stored procedure in MySQL with an OUT or INOUT parameter, it does not work. Even if I leave the stored procedure empty. The DDL is as follows:

CREATE DEFINER=`root`@`localhost` PROCEDURE `testing_inout`(`a` int,INOUT `b` int)
BEGIN

END

第一个参数是常规IN参数.第二个是INOUT参数(即使设置为OUT,同样的问题仍然存在)

The first parameter is a regular IN parameter. The second one is an INOUT paremeter (even if set as OUT the same problem persists)

当我调用此存储过程时,出现错误提示:

When I call this stored procedure, I get an error stating:

例程db_name的

OUT或INOUT参数2不是 变量或NEW伪变量在触发之前.

OUT or INOUT argument 2 for routine db_name.testing_inout is not a variable or NEW pseudo-variable in BEFORE trigger.

即使在存储过程中编写了代码,该错误仍然存​​在.我正在运行mysql版本5.1.41.

This error persists even if code is written inside the stored procedure. I am running mysql version 5.1.41.

这对我来说是个大问题,因为由于这个错误,我无法输出递归存储过程的结果.

This is a big problem for me because I cannot output the result of a recursive stored procedure because of this error.

推荐答案

对我有用

mysql> CREATE DEFINER=`root`@`localhost` PROCEDURE `testing_inout`(`a` int,INOUT `b` int)
    -> BEGIN
    -> 
    -> END
    -> ;
Query OK, 0 rows affected (0.00 sec)

第二个参数,因为它是inout,它需要是一个变量:

The second parameter because it's inout it need to be a variable:

mysql> set @c:=1;
Query OK, 0 rows affected (0.00 sec)

mysql> call testing_inout(1,@c);
Query OK, 0 rows affected (0.00 sec)

如果尝试此操作,它将返回1:

if you try this it will return 1:

delimiter |
CREATE DEFINER=`root`@`localhost` PROCEDURE `testing_inout`(`a` int,INOUT `b` int)
BEGIN
select b;
END
|
delimiter ;

mysql> call testing_inout(1,@c);
+------+
| b    |
+------+
|    1 |
+------+
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

这篇关于OUT或INOUT参数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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