Complete Oracle Character Set viewing and Modification

Source: Internet
Author: User

The following articles mainly introduce the concept of Oracle Character Set and the introduction of how to view and correctly modify the Oracle character set, as well as how to correctly view the Oracle character set in actual operations.Database Character Set OperationsThe steps are described.

What is the Oracle character set?

The Oracle character set is a collection of symbols for the interpretation of byte data. It can be divided into different sizes and have an inclusive relationship. Oracle supports the national language architecture, allowing you to store, process, and retrieve data in a localized language. It makes database tools, error messages, sorting order, date, time, currency, numbers, and calendar automatically adapt to localization languages and platforms.

The most important parameter that affects the character set of Oracle databases is the NLS_LANG parameter.

The format is as follows:

 
 
  1. NLS_LANG = language_territory.charset  

It has three components (language, region, and Character Set), each of which controls the NLS subset features.

Where:

Language specifies the Language of the server message, territory specifies the date and number format of the server, and charset specifies the character set. For example: AMERICAN _ AMERICA. ZHS16GBK

From the composition of NLS_LANG, we can see that the real impact on the database character set is actually the third part.

Therefore, if the character set between the two databases is the same as that in the third part, data can be imported and exported to each other. The preceding information is only prompted in Chinese or English.

View database character sets

This involves three Oracle character sets,

Character Set of the elasticsearch server;

Character Set of Oracle client;

The character set of the dmp file.

During data import, the three character sets must be consistent before the data can be correctly imported.

1. query character sets of Oracle server

There are many ways to find the character set of the Oracle server. The intuitive query method is as follows:

 
 
  1. SQL>select userenv(‘language’) from dual;  

The results are as follows: AMERICAN _ AMERICA. ZHS16GBK

2. How to query the dmp file Character Set

The dmp file exported using Oracle's exp tool also contains character set information. The 2nd and 3rd bytes of the dmp file record the character set of the dmp file. If the dmp file is not large, for example, only a few MB or dozens of MB, you can use UltraEdit to open it (in hexadecimal mode) and view the content of 2nd 3rd bytes, such as 0354, then, use the following SQL statement to find the corresponding Oracle character set:

 
 
  1. SQL> select nls_charset_name(to_number('0354','xxxx')) from dual;   
  2. ZHS16GBK  

If the dmp file is large, for example, 2 GB or above (this is also the most common case), you can use the following command (on a unix host) to open it slowly or completely ):

 
 
  1. cat exp.dmp |od -x|head -1|awk '{print $2 $3}'|cut -c 3-6  

Then, you can use the preceding SQL statement to obtain its character set.

3. query the character set of the Oracle client

This is relatively simple.

On windows, it is the NLS_LANG of OracleHome in the registry. You can also set it in the dos window, for example, set nls_lang = AMERICAN_AMERICA.ZHS16GBK.

In this way, only the environment variables in this window are affected.

On unix platforms, the environment variable NLS_LANG is used.

 
 
  1. $echo $NLS_LANG   
  2. AMERICAN_AMERICA.ZHS16GBK  

If the check result shows that the character sets on the server and client are inconsistent, change them to the same character set on the server.

Supplement:

(1). Database Server Character Set

 
 
  1. select * from nls_database_parameters  

The source is props $, which indicates the character set of the database.

(2). Client Character Set Environment

 
 
  1. select * from nls_instance_parameters  

It is derived from v $ parameter, which indicates the Oracle Character Set setting of the client, which may be a parameter file, environment variable, or registry.

(3). Session Character Set Environment

 
 
  1. select * from nls_session_parameters  

The source is v $ nls_parameters, which indicates the session's own settings. It may be the session's environment variable or the alter session is completed. If the session has no special settings, it will be consistent with nls_instance_parameters.

(4). Only when the character set of the client must be the same as that of the server can the non-Ascii characters of the database be correctly displayed. If multiple settings exist, alter session> environment variable> registry> parameter file

The character set must be consistent, but the language settings can be different. We recommend that you use English for language settings. For example, if the Oracle character set is zhs16gbk, The nls_lang can be American_America.zhs16gbk.

Related Article

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.