oracle数据库编码是GBK。
写一个python应用,在开头声明了编码 #-*-coding:utf-8-*- 可是插入数据的时候,依然乱码。后来查了好多资料,终于找到了办法。在程序的头部加入:
import os
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'
能够正常的insert和update中文
例:
# -*- coding: utf-8 -*-
import os
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'
import cx_Oracle
conn = cx_Oracle.connect('DATAREPOSITORY4TEST/DATAREPOSITORY4TEST@192.168.1.241:1521/tq')
cur = conn.cursor ()
cur.execute("insert into test_for_a (name,ino,sex,borndate,street,city,pkid,tq_createuser,tq_createdate,tq_updateuser,tq_updatedate,tq_isdelete) values ('abc',330621197601140000,'男',19760101,'a','acity',7,null,null,null,null,null)")
conn.commit()
cur.close ()
conn.close ()