oracle客户端sqlplus界面有乱码

[oracle@dd ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on ??? 2? 20 15:15:30 2013

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

----------------------------------------------------------------------------------------------

su - oracle

[oracle@dd ~]$ env
HOSTNAME=dd
SHELL=/bin/bash
TERM=vt100
HISTSIZE=1000
NLS_LANG=SIMPLIFIED CHINESE_CHINA.ZHS16GBK
USER=oracle

修改下export NLS_LANG="Simplified Chinese_China.UTF8"

 

重新连接恢复正常

[oracle@dd ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 2月 20 15:18:31 2013

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

-----------------------------------------------------------------------------

再设置为英文环境

[oracle@dd ~]$ export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"
[oracle@dd ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Wed Feb 20 15:27:52 2013

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

 

-------------------------------------------------------------------------------------------------------------

window 2003 32系统、oracle 11g数据库

1、连接windows 2003的oracle 11g


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 

2、查看客户端的字符集


SQL> select userenv('language') from dual;  
 
USERENV('LANGUAGE')  
----------------------------------------------------  
AMERICAN_AMERICA.ZHS16GBK  


3、查看服务端的字符集


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  


可以看到客户端与服务端的字符集都是一致的,均为ZHS16GBK。
4、创建dl_char表


SQL> create table dl_char (name varchar2(20));  
 
表已创建。  


5、插入数据


SQL> insert into dl_char values ('字符集的乱码问题');  
 
已创建 1 行。  


6、进行select查询


SQL> select * from dl_char;  
 
NAME  
--------------------  
字符集的乱码问题  


可以看得,现在显示为我刚才输入的值
7、更改客户端的字符集


C:\>SET NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1 


8、然后重新登录


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  


9、查看客户端的字符集


SQL> select userenv('language') from dual;  
USERENV('LANGUAGE')  
----------------------------------------------------  
AMERICAN_AMERICA.ZHS16GBK  


可以看到客户端的字符集已经变为AMERICAN_AMERICA.ZHS16GBK了
10、然后查看dl_char的值


SQL> select * from dl_char;  
 
NAME  
--------------------  
靠靠靠靠  


现在就出现了我前面说的4个靠字的问题,从上面的实验,可以看到产生4靠的原因为:客户端与服务端的字符集不一致,所以解决这个问题的方法就是在客户端设置与服务端一致的字符集


11、现在把客户端的字符集改成与服务端一致的字符集


C:\>SET NLS_LANG=ZHS16GBK 


12、然后登陆


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  


13、查看客户端与服务端的字符集


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  


14、现在客户端与服务端的字符集都一致了,在查看一下dl_char里的内容


SQL> select * from dl_char;  
 
NAME  
--------------------  
字符集的乱码问题  


         现在显示为正常的,4个靠字也没用在出现,所以以后在做exp/imp导出/导入或者客户端查询数据等操作的时候,一定要把客户端的字符集与服务端的字符集设置为同一个。

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值