使用 SQL 或其他变通方法访问存储过程的第二个结果集?Python\pyodbc [英] Access second result set of stored procedure with SQL or other work-around? Python\pyodbc

查看:47
本文介绍了使用 SQL 或其他变通方法访问存储过程的第二个结果集?Python\pyodbc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 python\pyodbc 并想访问存储过程的第二个结果集.据我所知,pyodbc 不支持多个结果集.此外,我无法修改存储过程.是否有任何选项可以使用 SQL 或其他一些变通方法访问第二个结果集?也许创建第二个存储过程,只返回第一个的第二个结果集?

解决方案

不需要任何花哨的东西.只需使用nextset:

<预><代码>导入pyodbcdb = pyodbc.connect("")q = db.cursor()q.execute("""从 INFORMATION_SCHEMA.TABLES 中选择前 5 个 *从 INFORMATION_SCHEMA.COLUMNS 中选择前 10 个 *""")表 = q.fetchall()q.nextset()列 = q.fetchall()断言 len(表)== 5断言 len(列)== 10

I'm using python\pyodbc and would like to access the second result set of a stored procedure. As near as I can tell, pyodbc does not support multiple result sets. Additionally, I can't modify the stored procedure. Are there any options to access the second result set using SQL or some other work-around? Perhaps create a second stored procedure that only returns the second result set of the first?

解决方案

No need for anything fancy. Just use nextset:


import pyodbc

db = pyodbc.connect ("")
q = db.cursor ()
q.execute ("""
SELECT TOP 5 * FROM INFORMATION_SCHEMA.TABLES
SELECT TOP 10 * FROM INFORMATION_SCHEMA.COLUMNS
""")
tables = q.fetchall ()
q.nextset ()
columns = q.fetchall ()

assert len (tables) == 5
assert len (columns) == 10

这篇关于使用 SQL 或其他变通方法访问存储过程的第二个结果集?Python\pyodbc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆