Linux下Oracle資料庫中文亂碼解決

來源:互聯網
上載者:User

Linux下Oracle資料庫中文亂碼解決
Linux下Oracle資料庫顯示中文亂碼

1.Oracle資料庫出現亂碼的原因:
作業系統與伺服器一致,但用戶端與伺服器字元集不一致
用戶端與伺服器一致,但作業系統與伺服器不一致
2.解決辦法:
設定相關的字元集,保證作業系統、用戶端、資料庫伺服器,保證這三者的字元集都相同。
3.針對情況:
設定用戶端的字元集與伺服器一致,假如伺服器的字元集為:UTF8(建議建立資料庫的時候用這個字元集,中英文都能相容)

1)查看作業系統字元集

# localeLANG=zh_CN.UTF-8LC_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.confLANG="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 functionsif [ -f ~/.bashrc ]; then        . ~/.bashrcfi# User specific environment and startup programsPATH=$PATH:$HOME/.local/bin:$HOME/binexport PATHexport ORACLE_BASE=/u01/app/oracle export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 export ORACLE_SID=orclexport PATH=$ORACLE_HOME/bin:$PATH export LD_LIBRARY_PATH=$ORACLE_HOME/libLANG=zh_CN.UTF-8; export LANG#NLS_LANG='SIMPLIFIED CHINESE_CHINA.AL32UTF8'; export NLS_LANGNLS_LANG='AMERICAN_AMERICA.AL32UTF8'; export NLS_LANG

3)oracle使用者下,臨時修改環境變數為en_US.UTF-8

$ su - oracle $ export  LANG=en_US.UTF-8$ env |grep LANGNLS_LANG=AMERICAN_AMERICA.AL32UTF8LANG=en_US.UTF-8

注意:用戶端的字元集和oracle 資料庫的字元集保持一致。

通過sqlplus驗證:

SQL> select USERNAME,ACCOUNT from AP_INTE_USR;    USERNAME               ACCOUNT ----------------------        --------------------------app應用                        test_app應用                              testyin 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.