Python3脚本读取Oracle数据库sql传入中文报编码错误:
UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 126-131: ordinal not in range(128)
解决方法:
import os
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'
如果是Python2 sql传入中文会查询为空[],解决方法:
import sys
reload(sys)
sys.setdefaultencoding('gb18030')
举例子:
d = u'秀'
sql = "SELECT * FROM customer_info WHERE customername LIKE '%{}%'".format(d)