如何从Python中的存储过程获取输出参数?

编程入门 行业动态 更新时间:2024-10-25 08:20:03
本文介绍了如何从Python中的存储过程获取输出参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我用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中的存储过程获取输出参数?

本文发布于:2023-10-28 23:17:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1538052.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:存储过程   参数   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!