[Reprint] view and modify the oracle server and client character set oracle server and client character set of the view and modify

View and modify the oracle server and client character set

 
https://www.cnblogs.com/lcword/p/5854186.html

 

First, what is the character set oracle 

Oracle character set is a set of symbols interpreted byte data, size of the points, the relationship of mutual tolerance. ORACLE support national language architecture allows you to use localized language to store, process, retrieve data. It makes database tools, error messages, sort order, date, time, currency, numbers, and calendar automatically adapt to the localization of language and platform. 

The most important parameters that affect oracle database character set is the NLS_LANG parameter. 

Its format is as follows: NLS_LANG = language_territory.charset 

it has three components (language, geography and character sets), each component controls a subset of NLS features. 

Of which: 

Language specify the server message language, territory specifies the server date and number format, charset specifies the character set. Such as:. AMERICAN _ AMERICA ZHS16GBK 

we can see from the composition of NLS_LANG, the real impact of the database character set is the third part. 

So the character set between the two databases as long as the third part we can import and export data with each other, affecting only the tips of information in front of a Chinese or English. 

Second, check the database character set 

which involves three aspects of the character set, 

one is oracel server-side character set; 

second is the oracle client-side character set; 

third is the dmp file character set. 

In doing data import requires the same three character sets can be imported correctly. 

1, the query oracle server-side character set 

There are many ways to find out oracle server-side character sets, more intuitive method of inquiry was the following that: 

SQL> select userenv ( 'language'  ) from dual;

results are similar to the following:. AMERICAN _ AMERICA ZHS16GBK 

2, how to query dmp document character set 

derived by the oracle exp tool dmp file also contains the character set information, the dmp file 2 and 3 bytes recorded dmp document character set. If not dmp file, such as only a few tens of M or M, can be used to open UltraEdit (hexadecimal), see the second and third bytes of content, such as 0354, and then the character corresponding to the following SQL it set: 

SQL> NLS_CHARSET_NAME the SELECT (to_number ( '0354', 'xxxx')) from Dual; 

ZHS16GBK 

If the dmp file is large, such as a 2G or more (this is the most common case), use a text editor to open very slowly or completely open, can use the following command (on unix host): 

CAT exp.dmp | the -X-OD | head -1 | awk '{}. 3 Print $ 2 $' | Cut -C 3-6 

then can be obtained by the above SQL it corresponds to the character set. 

3, the query oracle client-side character set 

This is relatively simple. 

In windows platform, which is the registry corresponding OracleHome of NLS_LANG. You can also set up their own in the dos window inside, such as: set nls_lang = AMERICAN_AMERICA.ZHS16GBK 

This affects only the environment variables inside the window. 

In the unix platform, it is the environment variable NLS_LANG. 

$ echo $ NLS_LANG 

AMERICAN_AMERICA.ZHS16GBK 

If the results of the inspection found that server-side and client-side character set is inconsistent, please unified modify the same with the server-side character set. 

Added: 

(1) database server character set. 

The SELECT * from NLS_DATABASE_PARAMETERS 

from props $, is a character set of the database. 

(2) The client character set environment 

select * from nls_instance_parameters 

it comes from v $ parameter, represents the set of the client's character set may be parameter files, environment variables or registry 

(3). Session character set environment 

select * from nls_session_parameters 

from v $ nls_parameters, indicates that the session own settings, environment variables may be a session or alter session is completed, if the session is no special setting, consistent with nls_instance_parameters. 

(4) Consistent with the requirements of the character set of client server to display non-Ascii characters in the database correctly. If there is more than set the time, alter session> Environment Variables> registry> parameter file 

character set consistent requirements, but they can set a different language, English language setting is recommended. The character set is zhs16gbk, it can be nls_lang American_America.zhs16gbk. 

Third, modify oracle character set 

Mentioned above, oracle character set has a mutually inclusive relationship. As us7ascii is the son of zhs16gbk, there is no problem on the interpretation of the data from us7ascii to zhs16gbk, there will be no loss of data. In all of the character set utf8 should be the maximum, because it is based on unicode, double-byte characters stored (and therefore take up more space on the storage). 

Once the database is created, the database character set theory can not be changed. Therefore, beginning in the design and installation to consider using the character set which is very important. According to Oracle's official description, character set conversion is from a sub-set of the superset supported, not vice versa. If there is no relationship between subset and superset of between two character sets, then character set conversion is not oracle support. The database server, the wrong character set changes will result in many unpredictable consequences that may seriously affect the normal operation of the database, so be sure to confirm before modifying the relationship between subset and superset of the two character sets exists. Generally speaking, unless a last resort, we do not propose to amend the oracle database server-side character set. Special note, subset and superset relationship does not exist between our two most common character set ZHS16GBK and ZHS16CGB231280, and therefore in theory conversion between these two characters is not supported. 

1, the server-side modified character set (not recommended) 

before the oracle 8, can directly modify the data dictionary table props $ to change the character set of the database. But after oracle8, at least three system table records the information database character set, only to change props $ table is not complete, may lead to serious consequences. The right to modify as follows: 

$ sqlplus / nolog 

SQL> conn / AS sysdba; if this time the database server is started, the first implementation SHUTDOWN IMMEDIATE command to close the database server, and then execute the following command: 

SQL> STARTUP MOUNT; 

The SQL> the ALTER the SYSTEM the ENABLE the RESTRICTED the SESSION; 

the SQL> the ALTER the SYSTEM the SET the JOB_QUEUE_PROCESSES = 0; 

the SQL> the ALTER the SYSTEM the SET AQ_TM_PROCESSES = 0; 

the SQL> the ALTER DATABASE the OPEN; 

the SQL> the ALTER DATABASE the CHARACTER the SET ZHS16GBK; 

the SQL> the ALTER DATABASE National the CHARACTER the SET ZHS16GBK; 

the SQL > SHUTDOWN IMMEDIATE; 

SQL> STARTUP 

Note: If no large object, there is no language translation impact during use, (remember the character set must be set ORACLE support, or can not start) by the above approach can be, but may there will be 'ORA-12717: can not ALTER DATABASE NATIONAL CHARACTER sET when NCLOB data exists' this message 

to solve this problem there are two ways 

one is by using keyword INTERNAL_USE modify regional settings, 

there is a use of re-create, but re-create a little complicated, so please use internal_use, 

SQL> SHUTDOWN IMMEDIATE; 

SQL> STARTUP MOUNT EXCLUSIVE; 

SQL> the ALTER the SYSTEM ENABLE RESTRICTED SESSION; 

The SQL> the ALTER the SYSTEM the SET the JOB_QUEUE_PROCESSES = 0; 

the SQL> the ALTER the SYSTEM the SET AQ_TM_PROCESSES = 0; 

the SQL> the ALTER DATABASE the OPEN; 

the SQL> the ALTER DATABASE the NATIONAL the CHARACTER the SET INTERNAL_USE the UTF8; 

the SQL> the SHUTDOWN immediate; 

the SQL> Startup; 

if done by the above approach, National charset region provided there is no problem 

2, modify the character set dmp file 

mentioned above, the second and third bytes dmp file records the character set information, thus directly modify the second and third bytes of the contents of the file on the dmp you can 'cheat' checks the oracle. This theory is also only from a subset to the superset can be modified, but in many cases can also be modified without the subset and superset relations, we used some of the character set, such as US7ASCII, WE8ISO8859P1, ZHS16CGB231280, ZHS16GBK basically can be changed. Because change is only dmp files, so little effect. 

More specific modification method, the simplest is modified with UltraEdit 2 and 3 bytes dmp file. 

For example want to change the file character set dmp ZHS16GBK, can be isolated by the following SQL code is hexadecimal character set corresponding to this type: SQL> select to_char (nls_charset_id (  'ZHS16GBK'), 'xxxx') from dual;

0354 

then 2,3 dmp file byte can be modified to 0354. 

If the dmp file is large, with ue can not open, we need to use the program's method

First, what is the character set oracle 

Oracle character set is a set of symbols interpreted byte data, size of the points, the relationship of mutual tolerance. ORACLE support national language architecture allows you to use localized language to store, process, retrieve data. It makes database tools, error messages, sort order, date, time, currency, numbers, and calendar automatically adapt to the localization of language and platform. 

The most important parameters that affect oracle database character set is the NLS_LANG parameter. 

Its format is as follows: NLS_LANG = language_territory.charset 

it has three components (language, geography and character sets), each component controls a subset of NLS features. 

Of which: 

Language specify the server message language, territory specifies the server date and number format, charset specifies the character set. Such as:. AMERICAN _ AMERICA ZHS16GBK 

we can see from the composition of NLS_LANG, the real impact of the database character set is the third part. 

So the character set between the two databases as long as the third part we can import and export data with each other, affecting only the tips of information in front of a Chinese or English. 

Second, check the database character set 

which involves three aspects of the character set, 

one is oracel server-side character set; 

second is the oracle client-side character set; 

third is the dmp file character set. 

In doing data import requires the same three character sets can be imported correctly. 

1, the query oracle server-side character set 

There are many ways to find out oracle server-side character sets, more intuitive method of inquiry was the following that: 

SQL> select userenv ( 'language'  ) from dual;

results are similar to the following:. AMERICAN _ AMERICA ZHS16GBK 

2, how to query dmp document character set 

derived by the oracle exp tool dmp file also contains the character set information, the dmp file 2 and 3 bytes recorded dmp document character set. If not dmp file, such as only a few tens of M or M, can be used to open UltraEdit (hexadecimal), see the second and third bytes of content, such as 0354, and then the character corresponding to the following SQL it set: 

SQL> NLS_CHARSET_NAME the SELECT (to_number ( '0354', 'xxxx')) from Dual; 

ZHS16GBK 

If the dmp file is large, such as a 2G or more (this is the most common case), use a text editor to open very slowly or completely open, can use the following command (on unix host): 

CAT exp.dmp | the -X-OD | head -1 | awk '{}. 3 Print $ 2 $' | Cut -C 3-6 

then can be obtained by the above SQL it corresponds to the character set. 

3, the query oracle client-side character set 

This is relatively simple. 

In windows platform, which is the registry corresponding OracleHome of NLS_LANG. You can also set up their own in the dos window inside, such as: set nls_lang = AMERICAN_AMERICA.ZHS16GBK 

This affects only the environment variables inside the window. 

In the unix platform, it is the environment variable NLS_LANG. 

$ echo $ NLS_LANG 

AMERICAN_AMERICA.ZHS16GBK 

If the results of the inspection found that server-side and client-side character set is inconsistent, please unified modify the same with the server-side character set. 

Added: 

(1) database server character set. 

The SELECT * from NLS_DATABASE_PARAMETERS 

from props $, is a character set of the database. 

(2) The client character set environment 

select * from nls_instance_parameters 

it comes from v $ parameter, represents the set of the client's character set may be parameter files, environment variables or registry 

(3). Session character set environment 

select * from nls_session_parameters 

from v $ nls_parameters, indicates that the session own settings, environment variables may be a session or alter session is completed, if the session is no special setting, consistent with nls_instance_parameters. 

(4) Consistent with the requirements of the character set of client server to display non-Ascii characters in the database correctly. If there is more than set the time, alter session> Environment Variables> registry> parameter file 

character set consistent requirements, but they can set a different language, English language setting is recommended. The character set is zhs16gbk, it can be nls_lang American_America.zhs16gbk. 

Third, modify oracle character set 

Mentioned above, oracle character set has a mutually inclusive relationship. As us7ascii is the son of zhs16gbk, there is no problem on the interpretation of the data from us7ascii to zhs16gbk, there will be no loss of data. In all of the character set utf8 should be the maximum, because it is based on unicode, double-byte characters stored (and therefore take up more space on the storage). 

Once the database is created, the database character set theory can not be changed. Therefore, beginning in the design and installation to consider using the character set which is very important. According to Oracle's official description, character set conversion is from a sub-set of the superset supported, not vice versa. If there is no relationship between subset and superset of between two character sets, then character set conversion is not oracle support. The database server, the wrong character set changes will result in many unpredictable consequences that may seriously affect the normal operation of the database, so be sure to confirm before modifying the relationship between subset and superset of the two character sets exists. Generally speaking, unless a last resort, we do not propose to amend the oracle database server-side character set. Special note, subset and superset relationship does not exist between our two most common character set ZHS16GBK and ZHS16CGB231280, and therefore in theory conversion between these two characters is not supported. 

1, the server-side modified character set (not recommended) 

before the oracle 8, can directly modify the data dictionary table props $ to change the character set of the database. But after oracle8, at least three system table records the information database character set, only to change props $ table is not complete, may lead to serious consequences. The right to modify as follows: 

$ sqlplus / nolog 

SQL> conn / AS sysdba; if this time the database server is started, the first implementation SHUTDOWN IMMEDIATE command to close the database server, and then execute the following command: 

SQL> STARTUP MOUNT; 

The SQL> the ALTER the SYSTEM the ENABLE the RESTRICTED the SESSION; 

the SQL> the ALTER the SYSTEM the SET the JOB_QUEUE_PROCESSES = 0; 

the SQL> the ALTER the SYSTEM the SET AQ_TM_PROCESSES = 0; 

the SQL> the ALTER DATABASE the OPEN; 

the SQL> the ALTER DATABASE the CHARACTER the SET ZHS16GBK; 

the SQL> the ALTER DATABASE National the CHARACTER the SET ZHS16GBK; 

the SQL > SHUTDOWN IMMEDIATE; 

SQL> STARTUP 

Note: If no large object, there is no language translation impact during use, (remember the character set must be set ORACLE support, or can not start) by the above approach can be, but may there will be 'ORA-12717: can not ALTER DATABASE NATIONAL CHARACTER sET when NCLOB data exists' this message 

to solve this problem there are two ways 

one is by using keyword INTERNAL_USE modify regional settings, 

there is a use of re-create, but re-create a little complicated, so please use internal_use, 

SQL> SHUTDOWN IMMEDIATE; 

SQL> STARTUP MOUNT EXCLUSIVE; 

SQL> the ALTER the SYSTEM ENABLE RESTRICTED SESSION; 

The SQL> the ALTER the SYSTEM the SET the JOB_QUEUE_PROCESSES = 0; 

the SQL> the ALTER the SYSTEM the SET AQ_TM_PROCESSES = 0; 

the SQL> the ALTER DATABASE the OPEN; 

the SQL> the ALTER DATABASE the NATIONAL the CHARACTER the SET INTERNAL_USE the UTF8; 

the SQL> the SHUTDOWN immediate; 

the SQL> Startup; 

if done by the above approach, National charset region provided there is no problem 

2, modify the character set dmp file 

mentioned above, the second and third bytes dmp file records the character set information, thus directly modify the second and third bytes of the contents of the file on the dmp you can 'cheat' checks the oracle. This theory is also only from a subset to the superset can be modified, but in many cases can also be modified without the subset and superset relations, we used some of the character set, such as US7ASCII, WE8ISO8859P1, ZHS16CGB231280, ZHS16GBK basically can be changed. Because change is only dmp files, so little effect. 

More specific modification method, the simplest is modified with UltraEdit 2 and 3 bytes dmp file. 

For example want to change the file character set dmp ZHS16GBK, can be isolated by the following SQL code is hexadecimal character set corresponding to this type: SQL> select to_char (nls_charset_id (  'ZHS16GBK'), 'xxxx') from dual;

0354 

then 2,3 dmp file byte can be modified to 0354. 

If the dmp file is large, with ue can not open, we need to use the program's method

Guess you like

Origin www.cnblogs.com/jinanxiaolaohu/p/12499601.html