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

时间:2018-06-07 21:02:08

标签: python sql-server pyodbc

我试图使用pyodbc获取SQL存储过程的输出参数。该过程位于MSSQL中,我可以从我的程序成功插入数据。这是sp:

的一部分
<p> Tickets Start at CA$ <?=the_field('price') ?></p>

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

1 个答案:

答案 0 :(得分:1)

这是来自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])

然后使用输出参数创建存储过程。

相关问题