我正在尝试执行以下脚本。但我既没有得到想要的结果,也没有得到错误消息,我无法找出我做错了什么。
import pyodbc
cnxn = pyodbc.connect("Driver={SQL Server Native Client 11.0};"
"Server=mySRVERNAME;"
"Database=MYDB;"
"uid=sa;pwd=MYPWD;"
"Trusted_Connection=yes;")
cursor = cnxn.cursor()
cursor.execute('select DISTINCT firstname,lastname,coalesce(middlename,\' \') as middlename from Person.Person')
for row in cursor:
print('row = %r' % (row,))
有什么想法吗?感谢您的帮助:)
必须与游标一起使用fetch方法。例如
编辑:
fetchall函数返回列表中剩余的所有行。
未读行由数据库驱动程序以压缩格式存储,通常从数据库服务器批量发送。
一次只读取所需的行将节省大量内存。
如果我们要一次处理一行,我们可以将光标本身用作一个interator 此外,我们可以简化它,因为cursor.execute()总是返回一个游标:
Documentation
相关问题 更多 >
编程相关推荐