What's NLS_LANG and usage

URL:http://download.oracle.com/docs/html/B13805_02/gblsupp.htm#BCEEEJGF

C Oracle Database Globalization Support

This appendix describes these Globalization Support topics:

  • About NLS_LANG Parameters

  • Commonly Used Values for NLS_LANG

  • NLS_LANG Settings in MS-DOS Mode and Batch Mode

C.1 About NLS_LANG Parameters

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 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/HOME ID /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

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.


See Also:

  • Oracle Database Platform Guide for Windows for more information about the subkey locations for multiple Oracle homes

  • Oracle Database Globalization Support Guide for information about the NLS_LANG parameter and Globalization Support initialization parameters


C.2 Commonly Used Values for NLS_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

C.3 NLS_LANG Settings in MS-DOS Mode and Batch Mode

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.

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
Arabic AR8ASMO8X
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


See Also:

" Globalization Support in the Directory" in Oracle Internet Directory Administrator's Guide for Oracle Internet Directory Globalization Support issues and required NLS_LANG environment variables for the various components and tools in an Oracle Internet Directory environment


Summary:
1.NLS_Lang format:

  NLS_LANG = LANGUAGE_TERRITORY . CHARACTER_SET

2. To check session NLS session parameters, note this doesn’t return the characterset set by NLS_LANG


SELECT * FROM NLS_SESSION_PARAMETERS;
SELECT USERENV ('language') FROM DUAL;

 

To find the NLS_LANG of your database one can run the following SQL:


SQL> SELECT * from NLS_DATABASE_PARAMETERS WHERE parameter IN ( 'NLS_LANGUAGE', 'NLS_TERRITORY', 'NLS_CHARACTERSET');

 

PARAMETER VALUE
—————————— —————————————-
NLS_LANGUAGE AMERICAN
NLS_TERRITORY AMERICA
NLS_CHARACTERSET WE8MSWIN1252

 

To get the possible value for language, territory and characterset you can check the view V$NLS_VALID_VALUES.
– parameter – possible values LANGUAGE, TERRITORY, CHARACTERSET


SELECT parameter, value FROM V$NLS_VALID_VALUES;

 

To change the client language
export NLS_LANG=BELGIUM_.WE8ISO8859P1
To change the client territory
export NLS_LANG=_BELGIUM.WE8ISO8859P1
To change the client characterset
export NLS_LANG=.AL32UTF8

 

3.setup in shell scripts:

  NLS_LANG='english_united kingdom.we8iso8859p1'; export NLS_LANG

4.其他:

Oracle NLS_LANG小结

关键字: oracle nls_lang character set 字符集 从客户那里拿到一个数据库,客户的数据库Server的字符集是JA16SJIS,使用export的Client端的NLS_LANG是 US7ASCII。问过DBA,得到的结论是由于Client使用的字符集是Server字符集的子集,所以导出的dump文件应该无效,以前也看过一本《循序渐进Oracle》,从那本书的说的情况看也应该是有问题的。但是自己还是试了试,报了很多错“长度不够”,原因是我的Oracle Instance字符集是AL32UTF8,没办法重新建了个JA16SJIS数据库,Console的NLS_LANG设置为 AMERICAN_AMERICA.US7ASCII,成功导入!表中的日文字符都没有问题。

很奇怪为什么能成功导入,做了个是试验:

创建了一个Test表,包含日文字符。
导出两次,NLS_LANG分别是AMERICAN_AMERICA.US7ASCII和AMERICAN_AMERICA.JA16SJIS,对比两次导出的dump文件,发现只有文件头不一样,其余部分基本一致,尤其是建表和插入的数据二进制部分完全一样。NLS_LANG的设置可能不会影响 dump文件的编码。通过查询Oracle网站得到这样的一句话

In Oracle9i the Export utility always exports user data, including Unicode data, in the character set of the database. The Import utility automatically converts the data to the character set of the target database.

也就是说,dump文件的数据的编码和源数据库的相同,不管Client的NLS_LANG如何设置。如果源数据库的字符集和目标数据库的字符集不一致,import时会自动转换。当然在不一致的情况下,源数据库的字符集一定要是目标数据库的子集。再查了下《循序渐进Oracle》,书中关于导入导出的例子使用的Oracle 8i,应该是作者偷懒把上一版的内容直接拿过来没更新。

另外再Oracle提供的关于NLS_LANG FAQ也列出了几条对NLS_LANG误解:

“NLS_LANG和数据库的字符集一样或许是正确的,但是经常是不对的。不要认为NLS_LANG必须和数据库的字符集一样,这经常是错的。” 《循序渐进Oracle》中说NLS_LANG一样的话可以提高性能,因为不需要字符集的转换。其实这样的转换不时发生在Server端,Client端转换完成后传递给Server端。我觉得,只要NLS_LANG是Server的字符集的子集就可以。

“NLS_LANG的字符集设置不会更改Client端的字符集。它只是用来告诉Oracle你在Client端使用什么字符集,你不能通过设置NLS_LANG去影响Client的字符集”。而且如果Client端的字符集和NLS_LANG不兼容,会导致数据库乱码。

“如果你不在Client端设置NLS_LANG,那么默认会使用Server的NLS_LANG设置,这是错的。如果Oracle在安装时没有设置NLS_LANG,那么NLS_LANG不会另外再设置,而是使用默认值:AMERICAN_AMERICA.US7ASCII。语言是 AMERICAN,区域是AMERICA,字符集US7ASCII”

“设置NLS_LANG的LANGUAGE 和 TERRITORY部分不会影响存储在数据库的字符。将NLS_LANG设置为JAPANESE_JAPAN.WE8MSWIN1252不会允许你存储日文。因为WE8MSWIN1252字符集不支持日文。但是设置成AMERICAN_AMERICA.JA16SJIS会允许你存储日文,假设你输入的字符是JA16SJIS,并且数据库的字符集也支持日文(如UTF8或者JA16SJIS)”

还需要注意的是:

SELECT USERENV ('language') FROM DUAL返回的是Session的LANGUAGE和 TERRITORY数据库的字符集。

参考: http://www.oracle.com/technology/tech/globalization/htdocs/nls_lang%20faq.htm

======================================
The NLS_LANG environment variable has three components:language, territory, and charset.
NLS_LANG is defined for each session by means of an environment variable or equivalent platform-specific mechanism. Different sessions connected to the same database can specify different values for NLS_LANG.

==============

 

你可能感兴趣的:(oracle,数据库,database,character,Components,globalization)