无法从存储过程中检索OUT参数(MySQL)

时间:2014-11-21 07:05:14

标签: python mysql django stored-procedures

我正在尝试从MySQL调用存储过程并获取OUT参数。 我有这样的代码,

从Python调用程序

from django.db import connection
# ...
cursor = connection.cursor()
out_arg1 = ""
args = [in_arg1, in_arg2, out_arg1]
result = cursor.callproc('some_procedure', args)
print(args[2], result[2])
cursor.close()
# ...

MySQL程序

CREATE DEFINER=`root`@`localhost` PROCEDURE `some_procedure`(IN `in_arg1` VARCHAR(255) CHARSET utf8, IN `in_arg2` VARCHAR(255) CHARSET utf8, OUT `out_arg1` VARCHAR(255) CHARSET utf8)
    MODIFIES SQL DATA
BEGIN

 proc:begin
 set out_arg1="Result";
 end;

END;

我已经检查了 args 以及 cursor.callproc 方法返回的结果,但没有数据发生变化。

为什么会发生这种情况?

提前致谢。

P.S。我试图从MySQL控制台调用此过程,一切正常。

1 个答案:

答案 0 :(得分:1)

使用这种方式

from django.db import connection
# ...
cursor = connection.cursor()
out_arg1 = ""
args = [in_arg1, in_arg2, out_arg1]
result = cursor.callproc('some_procedure', args)

cursor.execute('SELECT @some_procedure_2') 
print(cursor.fetchall())

#print(args[2], result[2])
cursor.close()
# ...