解决redhat enterprise linux 下oracle不能显示中文的方法
一、环境描述:
原始服务器 192.168.1.110 windows server 2003 系统 字符集为ZHS16GBK
新加服务器 192.168.1.120 redhat enterprise linux系统 字符集为WE8ISO8859PI
二、问题描述:
1.110服务器上的数据库为中文字符集,其内的数据表的多项列值为中文。
1.120服务器上的数据库中字符集并不支持ZHS16GBK,所以在将从1.110上导出来的.dmp文件导入到数据库中的时候便会出现以?代替中文字符的现象。
三、解决方法描述:
1、以root登录,设置linux系统语言为中文,即zh_CN(可在/etc/sysconfig/i18n文件中修改,当然前提是你需要有中文的安装包);设置完毕之后需要重启(远程登录的话好像只能重启了)或者按ctrl+alt+backspace组合键,使语言设置生效。
之所以设置系统语言为中文,是为了我们用客户端(比如secureCRT工具)登录服务器的时候可以显示中文,以验证oracle的正确。
sescureCRT中options-global options-general-Default session-
edit default setting-appearance-fonts设置喜欢的字体
characer encoding 选择uf8或者任意简体中文
2、以oracle用户登录编辑家目录下的.bash_profile文件,在其后添加 export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"
nls_lang是数据库的字符集变量,默认的为AMERICAN
3、注意dbca在创建实例的时候,默认的字符集等要和原平台的保持一致;
4、以sysdba来修改数据库的字符集,步骤如下:
SQL> conn /as sysdba
Connected.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 236000356 bytes
Fixed Size 451684 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
SQL> ALTER SESSION SET SQL_TRACE=TRUE;//语句跟踪
System altered.
SQL> ALTER SYSTEM ENABLE RESTRICTED SESSION;
System altered.
SQL> ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;
System altered.
SQL> ALTER SYSTEM SET AQ_TM_PROCESSES=0;
System altered.
SQL> alter database open;
Database altered.
SQL> ALTER DATABASE CHARACTER SET ZHS16GBK;
ALTER DATABASE CHARACTER SET ZHS16GBK
*
ERROR at line 1:
ORA-12712: new character set must be a superset of old character set
提示我们的字符集:新字符集必须为旧字符集的超集,这时我们可以跳过超集的检查做更改:
SQL> ALTER DATABASE character set INTERNAL_USE ZHS16GBK;
Database altered.
查看字符集是否改变:
SQL> select * from v$nls_parameters;
PARAMETER VALUE
---------------------------------------------------------------- ---------------
NLS_LANGUAGE ZHS16GBK ——已经改变,之前为AMERICAN
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD-MON-RR
NLS_DATE_LANGUAGE AMERICAN
NLS_CHARACTERSET ZHS16GBK
NLS_SORT BINARY
NLS_TIME_FORMAT HH.MI.SSXFF AM
PARAMETER VALUE
---------------------------------------------------------------- ---------------
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI
NLS_DUAL_CURRENCY $
NLS_NCHAR_CHARACTERSET UTF8
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE
19 rows selected.
重启刷新再检查一次:
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 236000356 bytes
Fixed Size 451684 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
Database opened.
SQL> select * from v$nls_parameters;
PARAMETER VALUE
---------------------------------------------------------------- ---------------
NLS_LANGUAGE ZHS16GBK
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD-MON-RR
NLS_DATE_LANGUAGE AMERICAN
NLS_CHARACTERSET ZHS16GBK
NLS_SORT BINARY
NLS_TIME_FORMAT HH.MI.SSXFF AM
PARAMETER VALUE
---------------------------------------------------------------- ---------------
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI
NLS_DUAL_CURRENCY $
NLS_NCHAR_CHARACTERSET UTF8
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE
19 rows selected.
4、最后导入.dmp文件
$imp test/test1234
____________________________________________________________________________________导入的提示信息
Import file: expdat.dmp > mydata.dmp
Enter insert buffer size (minimum is 8192) 30720>
Export file created by EXPORT:V11.02.00 via conventional path
import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
List contents of import file only (yes/no): no >
Ignore create error due to object existence (yes/no): no >
Import grants (yes/no): yes >
Import table data (yes/no): yes >
Import entire export file (yes/no): no > yes
—————————————————————————————————————————————————
上述步骤完成之后,如果在1.120服务器中运行select语句之后出现乱码(其实已经和之前出现?有很大的区别了,之所以出现乱码是因为终端字符集默认为UTF-8,我们可以更改linux下terminal的字符集为GBK登录试试看是否还有乱码出现),这时候也可以用客户端工具secureCRT以oracle用户登录192.168.1.120服务器,并设置后客户端的字符编码为简体中文,进行select语句查看,显示出来的就是中文了。这即是说,往数据表中插入数据的时候可以用客户端工具来完成。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/13332800/viewspace-705284/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/13332800/viewspace-705284/