PL/SQL cannot query and filter Chinese field solution

reason: 
The garbled PLSQL problem is caused by the inconsistency between the character set encoding of the ORACLE server and the character set encoding of the PLSQL. Similar garbled problems can be considered from whether the encoding is consistent. 
solve:
 
1. Query the character set encoding of the Oracle server to obtain the NLS_CHARACTERSET field value:
implement
  select  from  v$nls_parameters
         
 
 
Save the queried value, such as: NLS_CHARACTERSET = AL32UTF8
 
2. Query the language information of the Oracle server:
implement
NLS_CHARACTERSET 
SELECT  'AMERICAN_AMERICA.'  || PROPERTY_VALUE 
FROM  DATABASE_PROPERTIES
 
Save the queried value, such as: AMERICAN_AMERICA.AL32UTF8
 
3. Set the local environment variable. (PLSQL takes priority to get properties from environment variables)
   Right click on My Computer -> Properties -> Alerts System Properties -> Advanced -> Environment Variables -> System Variables column
   Add the following two records:
NLS_CHARACTERSET = AL32UTF8
NLS_LANG = AMERICAN_AMERICA.AL32UTF8
 
4. Restart PLSQL, OK. 

 

reason:

Client-side and server-side encodings are inconsistent

 

Learn about NLS_LANG

The NLS_LANG parameter consists of
NLS_LANG=<Language>_<Territory>.<Clients Characterset> 

 

View the Oracle server code: select * from sys.nls_database_parameters;

View client code: select * from sys.nls_session_parameters;

 

From the following server encoding we can get: NLS_LANG = AMERICAN_AMERICA.AL32UTF8

View the oracle server code: select * from sys.nls_database_parameters;

NLS_LANGUAGE  AMERICAN
NLS_TERRITORY  AMERICA
NLS_CURRENCY  $
NLS_ISO_CURRENCY  AMERICA
NLS_NUMERIC_CHARACTERS  .,
NLS_CHARACTERSET  AL32UTF8
NLS_CALENDAR  GREGORIAN
NLS_DATE_FORMAT  DD-MON-RR
NLS_DATE_LANGUAGE  AMERICAN
NLS_SORT  BINARY
NLS_TIME_FORMAT  HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT  DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT  HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT  DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY  $
NLS_COMP  BINARY
NLS_LENGTH_SEMANTICS  BYTE
NLS_NCHAR_CONV_EXCP  FALSE
NLS_NCHAR_CHARACTERSET AL16UTF16
NLS_RDBMS_VERSION 11.2.0.1.0


查看client编码   :select * from sys.nls_session_parameters;
NLS_LANGUAGE SIMPLIFIED CHINESE
NLS_TERRITORY CHINA
NLS_CURRENCY ¥
NLS_ISO_CURRENCY CHINA
NLS_NUMERIC_CHARACTERS .,
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD-MON-RR
NLS_DATE_LANGUAGE SIMPLIFIED CHINESE
NLS_SORT BINARY
NLS_TIME_FORMAT HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY ¥
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE

Obviously the encoding of the client side is inconsistent with that of the server side!!!! Solution:

 

Set environment variables to restart PLSQL

NLS_LANG=AMERICAN_AMERICA.AL32UTF8

 

This method is also suitable for using exp imp! To avoid Chinese garbled characters! Or some data garbled!

WINNT>   set NLS_LANG=AMERICAN_AMERICA.AL32UTF8Linux>    export NLS_LANG=AMERICAN_AMERICA.AL32UTF8

 

 

View NLS_LANG method
Windows use: echo %NLS_LANG%

C:\Users\Administrator>echo %NLS_LANG%
AMERICAN_AMERICA.AL32UTF8

The method of modifying the db code: (passed the test on oracle 11g ) -- risk operation....It is best not to use!!!!!!!!!
SQL> conn system as sysdba;
SQL> shutdown immediate;
SQL> startup mount ;
SQL> alter system enable restricted session;
SQL> alter system set job_queue_processes=0;
SQL> alter database open;
SQL> alter database character set internal_use AL32UTF8;
SQL> shutdown immediate;
SQL> startup 

 

Thanks for the original sharing, the original address: https://www.cnblogs.com/zhaobing0121/p/6909696.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325019489&siteId=291194637