PL/SQL无法查询过滤中文字段解决方案
Posted 秦潇湘
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PL/SQL无法查询过滤中文字段解决方案相关的知识,希望对你有一定的参考价值。
select
*
from
v$nls_parameters
NLS_CHARACTERSET
SELECT
\'AMERICAN_AMERICA.\'
|| PROPERTY_VALUE
FROM
DATABASE_PROPERTIES
NLS_CHARACTERSET = AL32UTF8
NLS_LANG = AMERICAN_AMERICA.AL32UTF8
原因:
客户端与服务器端编码不一致
了解下NLS_LANG的知识
NLS_LANG 参数组成
NLS_LANG=<Language>_<Territory>.<Clients Characterset>
查看Oracle服务端编码:select * from sys.nls_database_parameters;
从下面服务端 编码我们可以得到: NLS_LANG = AMERICAN_AMERICA.AL32UTF8
查看oracle服务端编码: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
明显客户端的编码和服务器端 的不一致!!!!解决办法:
设置环境变量 重启PLSQL
NLS_LANG=AMERICAN_AMERICA.AL32UTF8
此方法也适合用exp imp !以免中文有乱码出现!或部分数据乱码!
WINNT> set NLS_LANG=AMERICAN_AMERICA.AL32UTF8
Linux> export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
查看 NLS_LANG 的方法
Windows使用:echo %NLS_LANG%
C:\\Users\\Administrator>echo %NLS_LANG%
AMERICAN_AMERICA.AL32UTF8
修改db编码的办法:(在oracle 11g上通过测试) --风险操作....最好不要用!!!!!!!!
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
感谢原创分享,原文地址:https://www.cnblogs.com/zhaobing0121/p/6909696.html
以上是关于PL/SQL无法查询过滤中文字段解决方案的主要内容,如果未能解决你的问题,请参考以下文章
如何在 oracle pl/sql 查询中动态获取字段名称?