Nls_lang settings and Character Set Problems

Source: Internet
Author: User

My environment is RH linux 4, the database oracle 10.2, and the character set is AL32UTF8. This is the case: Use select to view the original data. Chinese characters are garbled, but java applications are normal. In linux, sqlplus is used to insert a Chinese character, and select is used for query. The newly inserted Chinese character is displayed normally, but cannot be queried by java applications. Utf8 is used for the database character set. The setting of nls_lang is NLS_LANG = american_america.AL32UTF8. Therefore, it is changed to NLS_LANG = american_america.UTF8 (edit and run. bash_profile), re-insert data, view with select, Chinese display garbled, but java application display normal. Modify NLS_LANG = american_america.ZHS16GBK and use select to query the data.

Today, I encountered the problem of SQL plus insert Chinese, mainly through the settings of nls_lang.

What is character set first? Character Set is a collection of symbols for interpretation of byte data. It has different sizes and relationships. For example, us7ascii is the subset of zhs16gbk. There will be no data interpretation problems from us7ascii to zhs16gbk, there will be no data loss. Oracle also requires that the export from the subset to the superset be supported. Otherwise, the export will not work. Utf8 should be the largest among all character sets because it is based on unicode and stores double-byte characters (so it occupies more space ).

Second, once the database is created, the character set of the database cannot be changed. Therefore, it is very important to consider which character set to use at the beginning of design and installation. The database character set should be a superset of the local character set of the operating system. The character set used by the customers who access the database determines which superset to choose, that is, the database character set should be the superset of all customer character sets.

Now, we will introduce some NLS_LANG parameters related to character sets,

NLS_LANG format:

NLS_LANG = language_territory.charset

There are three components (language, region, and Character Set), each of which controls the NLS subset features. Language indicates the language of the server message.

Territory specifies the date and number format of the server.

Charset

For example:

AMERICAN_AMERICA.US7SCII

AMERICAN _ AMERICA. ZHS16GBK

You can also define the NLS_LANG parameter in some subsets:

DICT. BASE data dictionary basic table version

DBTIMEZONE database Time Zone

NLS_LANGUAGE

NLS_TERRITORY Region

NLS_CURRENCY local currency character

NLS_ISO_CURRENCY ISO currency character

The NLS_NUMERIC_CHARACTERS decimal characters are separated by groups.

NLS_CHARACTERSET Character Set

NLS_CALENDAR calendar system

The default date format of NLS_DATE_FORMAT

Default date language of NLS_DATE_LANGUAGE

NLS_SORT character sorting Sequence

NLS_TIME_FORMAT

NLS_TIMESTAMP_FORMAT

......

View optional database character sets:
Col nls_charset_id for 99999
Col nls_charset_name for a35
Col hex_id for a5
Select nls_charset_id (value) nls_charset_id, value nls_charset_name, to_char (nls_charset_id (value), 'xxxx') hex_id
From v $ nls_valid_values
Where parameter = 'characterset ';

View the character set configuration of the current database:
Col parameter for a35
Col value for a35
Select * from v $ nls_parameters;
Or:
Select * from sys. props $;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.