2017-09-12 49 views
2

我有這個腳本執行正確,但我想將SQL腳本的結果打印到屏幕上。需要添加什麼?將Teradata SQL結果打印到命令行 - Python

感謝

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() 

回答

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]) 
+1

奏效,謝謝 – JD2775

+1

你也可以查看這個文檔:https://developer.teradata.com/tools/reference/teradata-python-modul Ë – PRMoureu