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 里面执行没问题
求帮忙

解决方案 »

  1.   

    数据里面015后面还有一堆空格呢
    解决根本问题应该把这种有空格的数据规范化
    临时方案就是where sno=qSno改成trim(sno)=qSno
      

  2.   


    我改完了 解决了 我还有一个问题
    我现在 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)
    结果 还是空的 只是为啥呀
      

  3.   

    qSno = input("") 
    sno=qSno这能得到结果吗?