Pyodbc - 读取存储过程的输出参数(SQL Server)

pri*_*his 2 python sql-server pyodbc

我正在尝试使用 pyodbc 获取 SQL Server 存储过程的输出参数。该过程位于 SQL Server 中,我可以从我的程序中成功插入数据。这是 SP 的一部分:

INSERT INTO Table(a,b,c,d,e,f,g) 
VALUES (@a,@b,@c,@d,@e,@f,@g);
SET @Result = 'Inserted'
RETURN @Result
Run Code Online (Sandbox Code Playgroud)

当我尝试读取代码中的结果变量时,它显示为空。

pri*_*his 5

这是来自python的调用,我使用了pyodbc:

cursor = self.db.cursor()

sql = """\
DECLARE @out nvarchar(max);
EXEC [dbo].[storedProcedure] @x = ?, @y = ?, @z = ?,@param_out = @out OUTPUT;
SELECT @out AS the_output;
"""

cursor.execute(sql, (x, y, z))
row = cursor.fetchone()
print(row[0])
Run Code Online (Sandbox Code Playgroud)

然后创建一个带有输出参数的存储过程。