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 里面执行没问题
求帮忙
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 里面执行没问题
求帮忙
解决方案 »
- 连接oracle数据库,返回-1034,搞了两天没搞定!!
- 统计邮件地址,有个字段存放着邮件地址(一个或多个,用逗号分隔)怎么统计?
- oracle升级问题?
- 如何计算两个时长的距离
- 如何提交所有session中的未提交的事务
- 如果一个表只有两个字段,但是两个字段都是外键行吗?(在oracle中建表时遇到的问题)
- 论坛谁是专家
- sql*plus 报ora01017错 invalid username/password
- 在本地计算机无法启动OracleDBConsoleorcl服务
- 哪里有sqlexpert3.2下载?
- 求Oracle 11.2.0.4安装补丁包patch 19692824 ,凝思系统总报错
- Oracle数据库查询语句来个大佬帮忙解答,万分感谢
解决根本问题应该把这种有空格的数据规范化
临时方案就是where sno=qSno改成trim(sno)=qSno
我改完了 解决了 我还有一个问题
我现在 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)
结果 还是空的 只是为啥呀
sno=qSno这能得到结果吗?