最近在做一个项目的时候,遇到了一个问题,在window 2003 系统oracle 11g数据库进行select的时候,结果为“靠靠靠靠”,当时的运维人员对oracle不太了解,所以就找到了我,我查看服务端与客户端的字符集,发现服务端为zhs16gbk,客户端为american_america.we8iso8858p1,当我把客户端修改与服务端一致字符集的时候,问题解决了。
下面是我做的一个技术文档,为以后的人员学习oracle做个实例说明。
环境为:
window 2003 32系统、oracle 11g数据库
1、连接windows 2003的oracle 11g
2、查看客户端的字符集
- C:\>sqlplus / as sysdba
- SQL*Plus: Release 11.2.0.1.0 Production on 星期一 5月 21 15:03:29 2012
- Copyright (c) 1982, 2010, Oracle. All rights reserved.
- 连接到:
- Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
- With the Partitioning, OLAP, Data Mining and Real Application Testing options
- SQL> select userenv('language') from dual;
- USERENV('LANGUAGE')
- ----------------------------------------------------
- AMERICAN_AMERICA.ZHS16GBK
- SQL> set linesize 100
- SQL> col parameter for a40
- SQL> col value for a40
- SQL> select * from nls_database_parameters where parameter like '%CHARACTERSET%%';
- PARAMETER VALUE
- ---------------------------------------- ----------------------------------------
- NLS_CHARACTERSET ZHS16GBK
- NLS_NCHAR_CHARACTERSET AL16UTF16
- SQL> create table dl_char (name varchar2(20));
- 表已创建。
- SQL> insert into dl_char values ('字符集的乱码问题');
- 已创建 1 行。
- SQL> select * from dl_char;
- NAME
- --------------------
- 字符集的乱码问题
- C:\>SET NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1
- C:\>sqlplus / as sysdba
- SQL*Plus: Release 11.2.0.1.0 Production on Mon May 21 15:06:55 2012
- Copyright (c) 1982, 2010, Oracle. All rights reserved.
- Connected to:
- Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
- With the Partitioning, OLAP, Data Mining and Real Application Testing options
- SQL> select userenv('language') from dual;
- USERENV('LANGUAGE')
- ----------------------------------------------------
- AMERICAN_AMERICA.ZHS16GBK
- SQL> select * from dl_char;
- NAME
- --------------------
- 靠靠靠靠
- C:\>SET NLS_LANG=ZHS16GBK
- C:\>sqlplus / as sysdba
- SQL*Plus: Release 11.2.0.1.0 Production on 星期一 5月 21 15:13:11 2012
- Copyright (c) 1982, 2010, Oracle. All rights reserved.
- 连接到:
- Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
- With the Partitioning, OLAP, Data Mining and Real Application Testing options
- SQL> select userenv('language') from dual;
- USERENV('LANGUAGE')
- ----------------------------------------------------
- SIMPLIFIED CHINESE_CHINA.ZHS16GBK
- SQL> select * from nls_database_parameters where parameter like '%CHARACTERSET%%';
- PARAMETER VALUE
- ---------------------------------------- ----------------------------------------
- NLS_CHARACTERSET ZHS16GBK
- NLS_NCHAR_CHARACTERSET AL16UTF16
- SQL> select * from dl_char;
- NAME
- --------------------
- 字符集的乱码问题