Python 2.7与Oracle的连接:丢失(波兰语)字符 [英] Python 2.7 connection to Oracle: loosing (Polish) characters

查看:193
本文介绍了Python 2.7与Oracle的连接:丢失(波兰语)字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Python 2.7连接到Oracle数据库. 当我使用时:

I connect from Python 2.7 to Oracle data base. When I use:

cursor.execute("SELECT column1 FROM table").fetchall()]

我对column1的值几乎是正确的,因为所有波兰语字符(ęóąśłżćń")都转换为ascii one("eoaslzcn").使用其他工具(例如SQLDeveloper)并使用相同的select语句,我可以获得适当的值.

I have got almost proper values for column1 because all Polish characters ("ęóąśłżćń") are converted to ascii one ("eoaslzcn"). Using another tool like SQLDeveloper and using the same select statement I get proper value.

推荐答案

@Mark Harrison-非常感谢!有用!我做了一个确切的指示:

@Mark Harrison - thank you very much ! It works! There is an exact instruction what I did:

我在Oracle中检查了什么语言:

I checked in Oracle what is the language:

SELECT USERENV ('language') FROM DUAL

答复为:

POLISH_POLAND.UTF8

然后我在Python中更改了NLS_LA值:

Then I changed NLS_LA value in Python:

os.environ['NLS_LANG'] = 'POLISH_POLAND.UTF8'

使用

print "%s, %s" % (name, surname)

我在命令行中

和> file.txt"在utf8中获得了一个(正确的)文件.

and "> file.txt" in command line I obtained a (proper) file in utf8.

这篇关于Python 2.7与Oracle的连接:丢失(波兰语)字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆