Oracle经典乱码问题——靠靠靠靠


最近在做一个项目的时候,遇到了一个问题,在window 2003 系统Oracle 11g数据库进行select的时候,结果为“靠靠靠靠”,当时的运维人员对oracle不太了解,所以就找到了我,我查看服务端与客户端的字符集,发现服务端为zhs16gbk,客户端为american_america.we8iso8858p1,当我把客户端修改与服务端一致字符集的时候,问题解决了。

下面是我做的一个技术文档,为以后的人员学习oracle做个实例说明。

环境为:

Window 2003 32系统、Oracle 11g数据库

1、连接windows 2003的oracle 11g

  1. C:\>sqlplus / as sysdba
  2. SQL*Plus: Release 11.2.0.1.0 Production on 星期一 5月 21 15:03:29 2012
  3. Copyright (c) 1982, 2010, Oracle. All rights reserved.
  4. 连接到:
  5. Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
  6. With the Partitioning, OLAP, Data Mining and Real Application Testing options
2、查看客户端的字符集
  1. SQL> select userenv('language') from dual;  
  2.  
  3. USERENV('LANGUAGE')  
  4. ----------------------------------------------------  
  5. AMERICAN_AMERICA.ZHS16GBK  
3、查看服务端的字符集
  1. SQL> set linesize 100  
  2. SQL> col parameter for a40  
  3. SQL> col value for a40  
  4. SQL> select * from nls_database_parameters where parameter like '%CHARACTERSET%%';  
  5.  
  6. PARAMETER                VALUE  
  7. ---------------------------------------- ----------------------------------------  
  8. NLS_CHARACTERSET             ZHS16GBK  
  9. NLS_NCHAR_CHARACTERSET       AL16UTF16  
可以看到客户端与服务端的字符集都是一致的,均为ZHS16GBK。 4、创建dl_char表
  1. SQL> create table dl_char (name varchar2(20));  
  2.  
  3. 表已创建。  
5、插入数据
  1. SQL> insert into dl_char values ('字符集的乱码问题');  
  2.  
  3. 已创建 1 行。  
6、进行select查询
  1. SQL> select * from dl_char;  
  2.  
  3. NAME  
  4. --------------------  
  5. 字符集的乱码问题  
可以看得,现在显示为我刚才输入的值 7、更改客户端的字符集
  1. C:\>SET NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1 
8、然后重新登录
  1. C:\>sqlplus / as sysdba  
  2.  
  3. SQL*Plus: Release 11.2.0.1.0 Production on Mon May 21 15:06:55 2012  
  4.  
  5. Copyright (c) 1982, 2010, Oracle.  All rights reserved.  
  6.  
  7.  
  8. Connected to:  
  9. Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production  
  10. With the Partitioning, OLAP, Data Mining and Real Application Testing options  
  • 1
  • 2
  • 下一页

相关内容