咨询热线:4006-75-4006
售前:9:00-23:30 备案:9:00-18:00 技术:7*24h
1.Oracle数据库出现乱码的原因:
操作系统与服务器一致,但客户端与服务器字符集不一致
客户端与服务器一致,但操作系统与服务器不一致
2.解决办法:
设置相关的字符集,保证操作系统、客户端、数据库服务器,保证这三者的字符集都相同。
3.针对情况:
设置客户端的字符集与服务器一致,假如服务器的字符集为:UTF8(建议创建数据库的时候用这个字符集,中英文都能兼容)
1)查看操作系统字符集
# locale LANG=zh_CN.UTF-8 LC_CTYPE="zh_CN.UTF-8" LC_NUMERIC="zh_CN.UTF-8" LC_TIME="zh_CN.UTF-8" LC_COLLATE="zh_CN.UTF-8" LC_MONETARY="zh_CN.UTF-8" LC_MESSAGES="zh_CN.UTF-8" LC_PAPER="zh_CN.UTF-8" LC_NAME="zh_CN.UTF-8" LC_ADDRESS="zh_CN.UTF-8" LC_TELEPHONE="zh_CN.UTF-8" LC_MEASUREMENT="zh_CN.UTF-8" LC_IDENTIFICATION="zh_CN.UTF-8" LC_ALL=
查看默认是zh_CN.UTF-8,rhel7配置文件是locale.conf
# vi /etc/locale.conf LANG="zh_CN.UTF-8"
2)查看数据库字符集
$ su - oracle
SQL> select userenv('language') from dual; USERENV('LANGUAGE') ---------------------------------------------------- AMERICAN_AMERICA.AL32UTF8
3)编辑linux 的NLS_LANG变量
$ vi .bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/.local/bin:$HOME/bin export PATH export ORACLE_BASE=/u01/app/oracle export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 export ORACLE_SID=orcl export PATH=$ORACLE_HOME/bin:$PATH export LD_LIBRARY_PATH=$ORACLE_HOME/lib.UTF-8; export LANG #NLS_LANG='SIMPLIFIED CHINESE_CHINA.AL32UTF8'; export NLS_LANG NLS_LANG='AMERICAN_AMERICA.AL32UTF8'; export NLS_LANG
3)oracle用户下,临时修改环境变量为en_US.UTF-8
$ su - oracle $ export.UTF-8 $ env |grep LANG NLS_LANG=AMERICAN_AMERICA.AL32UTF8.UTF-8
注意:客户端的字符集和oracle 数据库的字符集保持一致。
通过sqlplus验证:
SQL> select USERNAME,ACCOUNT from AP_INTE_USR; USERNAME ACCOUNT ---------------------- -------------------------- app应用 test_app 应用 testyin