Oracle 字符集设置

因为装Linux系统时选择的是英文版,所以当需要测试中文数据库时会出现乱码,这里记录一下我修改字符集的操作。

   

一些命令:

1、查看sqlplus客户编码:

$ echo  $NLS_LANG

2、查看系统编码:

$ locale

3、查看数据库字符集,执行如下查询:

select userenv('language') from dual;

   

一、安装中文字符集

   

列出可选安装包:

[root@node00 ~]# yum list kde*chinese

Loaded plugins: langpacks, product-id, subscription-manager

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

Available Packages

kde-l10n-Chinese.noarch 4.10.5-2.el7 rhel-media

安装中文字符集包:

[root@node00 ~]# yum install kde-l10n-Chinese.noarch

   

二、修改操作系统字符集

   

查询当前系统支持的字符集:

[root@node00 ~]# locale -a

…………………………….

zh_CN

zh_CN.gb18030

zh_CN.gb2312

zh_CN.gbk

zh_CN.utf8

zh_HK

zh_HK.big5hkscs

zh_HK.utf8

zh_SG

zh_SG.gb2312

zh_SG.gbk

zh_SG.utf8

zh_TW

zh_TW.big5

zh_TW.euctw

zh_TW.utf8

zu_ZA

zu_ZA.iso88591

zu_ZA.utf8

发现新增了以上中文相关字符集,重新设置操作系统字符集,这里采用zh_CN.utf8简体中文字符集:

[root@node00 ~]# echo $LANG

en_US.UTF-8

[root@node00 ~]# export LANG=zh_CN.utf8

[root@node00 ~]# echo $LANG

zh_CN.utf8

   

三、修改sqlplus字符集

   

编辑oracle用户的.bash_profile文件

[oracle@node00 dse]$ vim ~/.bash_profile

添加如下行:

export NLS_LANG="SIMPLIFIED CHINESE_CHINA.AL32UTF8"

使改变立即生效:

[oracle@node00 dse]$ source ~/.bash_profile

   

注:操作系统设置的是zh_CN.UTF-8,但在.bash_profile里面还不能直接将NLS_LANG设置为zh_CN.UTF-8,因为这个zh_CN.UTF8是字符集的localeID而不是字符集的名称,真正的名称叫SIMPLIFIED CHINESE_CHINA.AL32UTF8,如果设置成zh_CN.UTF8,oracle会报ORA-12705: Cannotaccess NLS data files or invalid environmentspecified错误。在.bash_profile里面加入NLS_LANG="SIMPLIFIED CHINESE_CHINA.AL32UTF8"; export NLS_LANG问题就解决了。

   

   

四、测试

   

[oracle@node00 dse]$ sqlplus / as sysdba

   

SQL*Plus: Release 11.2.0.4.0 Production on 星期一 11月 28 16:47:49 2016

   

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

   

   

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

   

SQL> select username from dba_users;

   

USERNAME

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

MGMT_VIEW

SYS

SYSTEM

DBSNMP

SYSMAN

中文

TEST001

OUTLN

FLOWS_FILES

MDSYS

ORDDATA

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

SQL> select userenv('language') from dual;

   

USERENV('LANGUAGE')

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

SIMPLIFIED CHINESE_CHINA.AL32UTF8

   

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

至此,问题解决。

   

参考文档:http://blog.csdn.net/heqiyu34/article/details/38479849

http://blog.csdn.net/u010288731/article/details/51376512

http://blog.csdn.net/heqiyu34/article/details/38479849

   

   

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

Windows 下修改 Oracle 字符集

 

  

原文地址:https://www.cnblogs.com/j-notes/p/6524134.html