我有正确执行的脚本,但我想将SQL脚本的结果打印到屏幕上。需要添加什么?
由于
import teradata
import sys
import pwd
def main():
udaExec = teradata.UdaExec (appName="DataWarehouseConnectionTest", version="1.0", logConsole=True)
mConn = udaExec.connect(method="odbc",dsn="test",username=pwd.username,password=pwd.password)
mConn.execute('SELECT COUNT(*) FROM DB.Test')
if __name__ == "__main__":
main()
答案 0 :(得分:2)
您应该能够通过直接循环表达式来打印查询结果:
for line in mConn.execute('SELECT COUNT(*) FROM DB.Test'):
print(line)
或者在你的情况下:
res = mConn.execute('SELECT COUNT(*) FROM DB.Test')
if res:
print(res[0])