1. 程式人生 > >【Oracle】詳解Oracle中NLS_LANG變量的使用

【Oracle】詳解Oracle中NLS_LANG變量的使用

make fault tro territory font pin onclick 添加 其中

目錄結構:

contents structure [-]
  1. 關於NLS_LANG參數
  2. NSL_LANG常用的值
  3. 在MS-DOS模式和Batch模式中設置NLS_LANG
  4. 註冊表中NLS_LANG和系統環境變量中的NLS_LANG
  5. 參考文章

1,關於NLS_LANG參數

Oracle provides Globalization Support that enables users to interact with a database in their own language, as defined by the NLS_LANG

parameter. When you install Oracle Database Client components, Oracle Universal Installer sets the NLS_LANG parameter in the registry.

The locale setting of your operating system determines the value of the NLS_LANG parameter at installation. Table C-1 lists the operating system locale and NLS_LANG

value mappings.

The NLS_LANG parameter is stored in the registry under the HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\HOMEID\NLS_LANG subkey, where ID is the unique number identifying the Oracle home.

The NLS_LANG parameter uses the following format:

NLS_LANG = LANGUAGE_TERRITORY.CHARACTER_SET 
Oracle提供全球化的支持,通過定義NLS_LANG參數能夠讓用戶用他們自己的語言使用數據庫。當安裝Oracle數據庫客戶端的時候,安裝程序通常會在註冊表中設置NLS_LANG參數。
在安裝中,操作系統的區域設置會決定NLS_LANG參數的值。表C-1列出了操作系統區域和NLS_LANG的對照表。
NLS_LANG參數被存儲在註冊表中的HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\HOMEID\NLS_LANG子項下,其中ID是識別Oracle home的唯一數字。 NLS_LANG參數使用如下的格式: NLS_LANG = LANGUAGE_TERRITORY.CHARACTER_SET

where:

Parameter Description
LANGUAGE Specifies the language and conventions for displaying messages, day name, and month name.
TERRITORY Specifies the territory and conventions for calculating week and day numbers.
CHARACTER_SET Controls the character set used for displaying messages.

2 NSL_LANG常用的值

Table C-1 lists commonly used NLS_LANG values for various operating system locales:

Table C-1 NLS_LANG Parameter Values

Operating System Locale NLS_LANG Value
Arabic (U.A.E.) ARABIC_UNITED ARAB EMIRATES.AR8MSWIN1256
Bulgarian BULGARIAN_BULGARIA.CL8MSWIN1251
Catalan CATALAN_CATALONIA.WE8MSWIN1252
Chinese (PRC) SIMPLIFIED CHINESE_CHINA.ZHS16GBK
Chinese (Taiwan) TRADITIONAL CHINESE_TAIWAN.ZHT16MSWIN950
Croatian CROATIAN_CROATIA.EE8MSWIN1250
Czech CZECH_CZECH REPUBLIC.EE8MSWIN1250
Danish DANISH_DENMARK.WE8MSWIN1252
Dutch (Netherlands) DUTCH_THE NETHERLANDS.WE8MSWIN1252
English (United Kingdom) ENGLISH_UNITED KINGDOM.WE8MSWIN1252
English (United States) AMERICAN_AMERICA.WE8MSWIN1252
Estonian ESTONIAN_ESTONIA.BLT8MSWIN1257
Finnish FINNISH_FINLAND.WE8MSWIN1252
French (Canada) CANADIAN FRENCH_CANADA.WE8MSWIN1252
French (France) FRENCH_FRANCE.WE8MSWIN1252
German (Germany) GERMAN_GERMANY.WE8MSWIN1252
Greek GREEK_GREECE.EL8MSWIN1253
Hebrew HEBREW_ISRAEL.IW8MSWIN1255
Hungarian HUNGARIAN_HUNGARY.EE8MSWIN1250
Icelandic ICELANDIC_ICELAND.WE8MSWIN1252
Indonesian INDONESIAN_INDONESIA.WE8MSWIN1252
Italian (Italy) ITALIAN_ITALY.WE8MSWIN1252
Japanese JAPANESE_JAPAN.JA16SJIS
Korean KOREAN_KOREA.KO16MSWIN949
Latvian LATVIAN_LATVIA.BLT8MSWIN1257
Lithuanian LITHUANIAN_LITHUANIA.BLT8MSWIN1257
Norwegian NORWEGIAN_NORWAY.WE8MSWIN1252
Polish POLISH_POLAND.EE8MSWIN1250
Portuguese (Brazil) BRAZILIAN PORTUGUESE_BRAZIL.WE8MSWIN1252
Portuguese (Portugal) PORTUGUESE_PORTUGAL.WE8MSWIN1252
Romanian ROMANIAN_ROMANIA.EE8MSWIN1250
Russian RUSSIAN_CIS.CL8MSWIN1251
Slovak SLOVAK_SLOVAKIA.EE8MSWIN1250
Spanish (Spain) SPANISH_SPAIN.WE8MSWIN1252
Swedish SWEDISH_SWEDEN.WE8MSWIN1252
Thai THAI_THAILAND.TH8TISASCII
Spanish (Mexico) MEXICAN SPANISH_MEXICO.WE8MSWIN1252
Spanish (Venezuela) LATIN AMERICAN SPANISH_VENEZUELA.WE8MSWIN1252
Turkish TURKISH_TURKEY.TR8MSWIN1254
Ukrainian UKRAINIAN_UKRAINE.CL8MSWIN1251
Vietnamese VIETNAMESE_VIETNAM.VN8MSWIN1258

3 在MS-DOS模式和Batch模式中設置NLS_LANG

Before you can use Oracle utilities such as SQL*Plus, SQL Loader, Import, and Export in MS-DOS mode, make sure that you have set the character set field of the NLS_LANG parameter for the session to the correct value.

This is required because MS-DOS mode uses, with a few exceptions, a different character set (or code-page) from Windows (ANSI code-page), and the default Oracle home NLS_LANG parameter in the registry is always set to the appropriate Windows code-page. If you do not set the NLS_LANG parameter for the MS-DOS mode session correctly, incorrect character conversion can corrupt error messages and data.

For Japanese, Korean, Simplified Chinese, and Traditional Chinese, the MS-DOS code-page is identical to the ANSI code-page. In this case, you do not need to set the NLS_LANG parameter in MS-DOS mode.

Similarly, in batch mode, set the correct character set value of NLS_LANG by inserting a SET NLS_LANG command at the start of the batch procedure, according to the character set of the files to be processed in the procedure.

在你使用Oracle應用之前,比如在MS-DOS模式中使用SQL*Plus,SQL Loader,Import,和Export,確保你已經在本次會話中正確的設置了字符集屬性和NLS_LANG參數屬性。

這是必須的,因為MS-DOS模式的使用會帶有一些的來著Windows(ANSI code-page)的不同字符集設置的異常,在註冊表中默認的Oracle home NLS_LANG參數總是會被設置成適合Windows code-page的值。
如果你在MS-DOS模式中不正確的設置NLS_LANG參數的值,那麽錯誤的字符轉換將會損壞信息和數據。
對於日文,韓文,簡體中文和繁體中文,MS—DOS code-page 和ANSI code-page的值一樣。在這種情況下,你不需要在MS-DOS模式中設置NLS_LANG參數的值。

同樣的,在Batch模式中,根據程序運行過程中被處理的文件字符,通過插入SET LANG_LANG 命令設置正確的NLS_LANG值。

Table C-2 lists the Oracle character sets that correspond to the MS-DOS mode for various operating system locales:

Table C-2 Oracle Character Sets for Operating System Locales

Operating System Locale Character Set
Catalan WE8PC850
Chinese (PRC) ZHS16GBK
Chinese (Taiwan) ZHT16MSWIN950
Czech EE8PC852
Danish WE8PC850
Dutch WE8PC850
English (United Kingdom) WE8PC850
English (United States) US8PC437
Finnish WE8PC850
French WE8PC850
German WE8PC850
Greek EL8PC737
Hungarian EE8PC852
Italian WE8PC850
Japanese JA16SJIS
Korean KO16MSWIN949
Norwegian WE8PC850
Polish EE8PC852
Portuguese WE8PC850
Romanian EE8PC852
Russian RU8PC866
Slovak EE8PC852
Slovenian EE8PC852
Spanish WE8PC850
Swedish WE8PC850
Turkish TR8PC857
Catalan WE8PC850

4,註冊表中NLS_LANG和系統環境變量中的NLS_LANG

當用戶安裝好Oracle客戶端後會在註冊表中出現NLS_LANG的註冊信息,在操作系統的環境變量中用戶也可以設置自己的NLS_LANG的值。

但是需要註意:

註冊表中的NLS_LANG是用於對應Oracle數據庫與windows 的code-page值的,這個值是在安裝的過程中自動添加的,一般不要去修改,如果修改後NLS_LANG的值與code-page的值不對應的話,會出現不同字符的異常。

系統環境變臉中NLS_LANG是用於對應Oracle數據顯示的,這個值在安裝完成後可能會有,也可能沒有,是可以修改的,如果希望以中文顯示則修改為 NLS_LANG=SIMPLIFIED CHINESE_CHINA.ZHS16GBK ,也可以是英文的 NLS_LANG=AMERICAN_AMERICA.UTF8 ,建議在使用Oracle數據庫之間將這裏的NLS_LANG設置為英文顯示。

5,參考文章

C Oracle Database Client Globalization Support

【Oracle】詳解Oracle中NLS_LANG變量的使用