我用Google搜索了一下,但是也许我没有在搜索框中输入正确的魔咒.
I've googled around a bit, but maybe I didn't put the correct magik incantation into the search box.
有人知道如何从Python的存储过程中获取输出参数吗?我正在使用pymssql调用存储过程,但不确定是否使用正确的语法来获取输出参数.我不认为可以使用任何其他数据库模块,因为我是从Linux机器上运行该模块来连接到MS Server上的mssql数据库的.
Does anyone know how to get output parameters from a stored procedure in Python? I'm using pymssql to call a stored procedure, and I'm not sure of the correct syntax to get the output parameter back. I don't think I can use any other db modules since I'm running this from a Linux box to connect to a mssql database on a MS Server.
import pymssql con = pymssql.connect(host='xxxxx',user='xxxx',password='xxxxx',database='xxxxx') cur = con.cursor() query = "EXECUTE blah blah blah" cur.execute(query) conmit() con.close()推荐答案
我不是python专家,但在简短阅读 DB-API 2.0 我相信您应该使用游标的"callproc"方法,如下所示:
I'm not a python expert but after a brief perusing of the DB-API 2.0 I believe you should use the "callproc" method of the cursor like this:
cur.callproc('my_stored_proc', (first_param, second_param, an_out_param))然后,您将在"an_out_param"变量中将结果存储在out参数的返回值中.
Then you'll have the result in the returned value (of the out param) in the "an_out_param" variable.
更多推荐
如何从Python中的存储过程获取输出参数?
发布评论