Sac*_*yal 3 unicode cx-oracle oracle11g python-2.7
我在用
Python 2.7
cx_Oracle 6.0.2
Run Code Online (Sandbox Code Playgroud)
我在我的代码中做这样的事情
import cx_Oracle
connection_string = "%s:%s/%s" % ("192.168.8.168", "1521", "xe")
connection = cx_Oracle.connect("system", "oracle", connection_string)
cur = connection.cursor()
print "Connection Version: {}".format(connection.version)
query = "select *from product_information"
cur.execute(query)
result = cur.fetchone()
print result
Run Code Online (Sandbox Code Playgroud)
我得到了这样的输出
连接版本:11.2.0.2.0
(1, 你'????????????', '测试')
我正在使用以下查询在 oracle 数据库中创建表
CREATE TABLE product_information
( product_id NUMBER(6)
, product_name NVARCHAR2(100)
, product_description VARCHAR2(1000));
Run Code Online (Sandbox Code Playgroud)
我使用以下查询插入数据
insert into product_information values(2, '????', 'teting');
Run Code Online (Sandbox Code Playgroud)
编辑 1
询问: SELECT * from NLS_DATABASE_PARAMETERS WHERE parameter IN ( 'NLS_LANGUAGE', 'NLS_TERRITORY', 'NLS_CHARACTERSET');
结果
NLS_LANGUAGE:美国,NLS_TERRITORY:美国,NLS_CHARACTERSET:AL32UTF8
我解决了这个问题。
首先我NLS_LANG=.AL32UTF8
在安装Oracle的系统中添加了环境变量其次我在cx_Oracle的connect函数中传递了encoding和nencoding参数,如下所示。
cx_Oracle.connect(username, password, connection_string,
encoding="UTF-8", nencoding="UTF-8")
Run Code Online (Sandbox Code Playgroud)
这个问题也在这里讨论https://github.com/oracle/python-cx_Oracle/issues/157
归档时间: |
|
查看次数: |
4286 次 |
最近记录: |