在安装完成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、然后查看客户端配置,需要和服务器一样

cat /etc/sysconfig/i18n

用root用户在/etc/sysconfig/i18n里添加

NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

 (即和服务端一样的编码)

3、或者在.bash_profile文件配置

export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

4、运行 .bash_profile文件,让刚改的文件进行生效

sh ~/.bash_profile

5、重新链接或退出重新登录

相关文章:

  • 2022-02-05
  • 2022-02-17
  • 2021-05-08
  • 2021-12-03
  • 2021-07-23
  • 2021-12-10
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-24
  • 2021-05-22
相关资源
相似解决方案