作者:娶位红太郎_442 | 来源:互联网 | 2023-05-17 12:52
在安装完成cx_Oracle后,importcx_Oracle时报错,首先查看.bash_profile文件中环境变量配置#.bash_profile#Getthealias
在安装完成cx_Oracle后,import cx_Oracle时报错,首先查看.bash_profile文件中环境变量配置
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/client_1
export PATH=$ORACLE_HOME/bin:$PATH
然后在.bash_profile中加入
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
即可,这时,使用cx_Oracle已经没问题了,但是当向数据库插入中文时有出现问题,此时
1、先查看客户端和服务端的编码集
服务端:SELECT * FROM nls_database_parameters;--ZHS16GBK
客户端:SELECT * FROM Nls_Instance_Parameters;
2、然后查看客户端配置,需要和服务器一样
用root用户在/etc/sysconfig/i18n里添加
NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
(即和服务端一样的编码)
3、或者在.bash_profile文件配置
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
4、运行 .bash_profile文件,让刚改的文件进行生效
5、重新链接或退出重新登录