Oracle用戶端出現亂碼的解決

來源:互聯網
上載者:User

1. NLS_LANG 參數組成
NLS_LANG參數由以下部分組成:
NLS_LANG=_.

NLS_LANG各部分含義如下:
LANGUAGE指定:
-Oracle訊息使用的語言
-日期中月份和日顯示
TERRITORY指定
-貨幣和數字格式
-地區和計算星期及日期的習慣
CHARACTERSET:
-控制用戶端應用程式使用的字元集
通常設定或者等於用戶端(如Windows)字碼頁
或者對於unicode應用設定為UTF8

在Windows上查看當前系統的字碼頁可以使用chcp命令:
E:\>chcp
活動的字碼頁: 936

字碼頁936也就是中文字元集 GBK,在Microsoft的官方網站上,我們可以遭到關於936字碼頁的具體編碼規則


2. 查看 NLS_LANG 的方法
Windows使用:

echo %NLS_LANG%
如:
E:\>echo %NLS_LANG%
AMERICAN_AMERICA.ZHS16GBK

Unix使用:

env|grep NLS_LANG
如:
/opt/oracle>env|grep NLS_LANG
NLS_LANG=AMERICAN_CHINA.ZHS16GBK

Windows用戶端設定,可以在註冊表中更改NLS_LANG,具體索引值位於:
HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\HOMExx\
xx指存在多個ORACLE_HOME時系統編號。


3. 查看資料庫當前字元集參數設定
SELECT * FROM v$nls_parameters;

select * from nls_database_parameters

select userenv(‘language’) from dual;


4. 查看資料庫可用字元集參數設定
SELECT * FROM v$nls_valid_values;


5. 用戶端 NLS_LANG 的設定方法
Windows:
# 常用中文字元集
set NLS_LANG=SIMPLIFIED CHINESE_CHINA.ZHS16GBK
# 常用unicode字元集
set NLS_LANG=american_america.AL32UTF8
可以通過修改註冊表索引值永久設定
HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\HOMExx\NLS_LANG

Unix:
# 常用unicode字元集
export NLS_LANG=american_america.AL32UTF8
# 常用中文字元集
export NLS_LANG="Simplified Chinese_china".ZHS16GBK
可以編輯 bash_profile 檔案進行永久設定
vi .bash_profile
NLS_LANG="Simplified Chinese_china".ZHS16GBK export NLS_LANG
# 使 bash_profile 設定生效
source .bash_profile

相關文章

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.