import os
import cx_Oracle
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'
conn = cx_Oracle.connect('system/Pzm971003@localhost:1521/T_S_C')
curs = conn.cursor()
qSno = "015"
curs.execute('''select * from sc
where sno=:sno
''', sno=qSno
)
res = curs.fetchall()
print(res)
conn.commit()
curs.close()
conn.close()
這樣輸出 是空串列
但是 換成 curs.execute("select * from sc")
會輸出 [('015 ', '5 ', '55 '), ('001 ', '1 ', '80 '), ('002 ', '2 ', '80 '), ('201912121 ', '3 ', '80 ')]
上面的那個陳述句在sql server 里面執行沒問題
求幫忙
uj5u.com熱心網友回復:
資料里面015后面還有一堆空格呢解決根本問題應該把這種有空格的資料規范化
臨時方案就是where sno=qSno改成trim(sno)=qSno
uj5u.com熱心網友回復:
我改完了 解決了 我還有一個問題
我現在 curs.execute("select * from sc") res = curs.fetchall() print(res) 會輸出[('2019307030107', '1 ', '85 '), ('2019307030108', '2 ', '80 ')]
然后我把程式改成
qSno = input("")
curs.execute('''select * from sc
where trim(sno)=:sno
''', sno=qSno
)
res = curs.fetchall()
print(res)
for i in res:
print(i)
結果 還是空的 只是為啥呀
uj5u.com熱心網友回復:
qSno = input("")sno=qSno
這能得到結果嗎?
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/38301.html
標籤:基礎和管理
