What is NLS_LANG?
NLS_LANG is an environment variable used to define the language, region, and Character Set attributes. For non-English character sets, the setting of NLS_LANG is very important.
NLS: 'national Language Support (NLS) 'when we set an nls, we actually specify some expressions specific to its Language when Oracle stores data, for example, if we select "chinese", how to store chinese characters, how to sort by rules, and how to represent the currency, the date format will be set.
NLS_LANG format
NLS_LANG = language_territory.charset
For common values, see Oracle Database Client Globalization Support
Setting of NLS_LANG
In Unix, NLS_LANG is an environment variable. In Windows, NLS_LANG is generally set in the registry.
Settings in Unix
- Export NLS_LANG = AMERICAN_AMERICA.WE8ISO8859P1
In WindowsHKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\HOMEx\NLS_LANG
If there are multiple oracle products, there may be multiple HOMEx products, such as HOME0 and HOME1.. Generally, there is the registration item NLS_LANG.
In Windows, you can also set NLS_LANG to an environment variable. However, this is rarely done, but it is generally set in the registry.
NLS_LANG in DB
DB also has its own NLS_LANG parameter to identify the language, region, and Character Set of the database. You can use the following SQL statements to check,
- SELECT*FROMV $ nls_parameters;
- OR
- SELECTUSERENV ('Language')FROMDUAL;
The client's NLS_LANG and the DB's NLS_LANG
The NLS_LANG of DB should be consistent with the NLS_LANG in the client environment variables as much as possible.
Setting the NLS_LANG Environment Variable for Oracle Databases provides a way to maintain consistency.
So why do we need to be consistent? This is because if the character set does not match, it is possible that the character conversion error may occur during the conversion between DB and Client. For example, the example in Oracle nls_lang tips.
Refer:
NLS_LANG FAQ
Oracle Database Client Globalization Support
Setting the NLS_LANG Environment Variable for Oracle Databases