数据库中文乱码 ORACLE NLS_LANG LINUX LANG

来源:互联网 发布:2016淘宝店铺重开技术 编辑:程序博客网 时间:2024/04/29 22:20

要维护数据库时候 经常使用LINUX系统和远程SHELL客户端连接到ORACLE数据库. 使用上面的SQLPLUS  LSNRCTL RMAN工具

经常检查TRC文件,ORA文件 等.  要是出现乱码就糟糕了.

因为 你来之前别人已经装好了ORACLE 并且设置了中文.....

以前习惯了英文...  所以被中文撞了腰.

 

终端使用的 PUTTY  SSH  SECUTP   XMAGRE等

这里涉及到系统 和数据库 两块东. 不要搞乱自己哦

EXPORT  LANG  ==> 是定义系统语言的

EXPORT NLS_LANG==> 定义数据库语言的

 

这些 我一般放在/home/oracle/.bash_profile    其他人喜欢放在/home/oracle/.bashrc里

设置之前了解下系统目前语言和支持的语言.

先讲 系统的LANG

cat /etc/sysconfig/i18n    系统默认语言

/usr/share/i18n/SUPPORTED  包含系统支持的本地语言/usr/local/share/i18n/SUPPORTED  添加自定义的本地语言到这个文件
 
我的LINUX系统默认是英文 附加了中文支持
因此我的ORACLE用户下的环境变量 LANG=zh_CN.UTF-8
这样 保存 然后source /home/oracle/.bash_profile 生效下
df -h  中文标题出来了.
语言(Language), 地域 (Territory) 和字符集(Codeset)。一个locale的书写格式为: 语言[_地域[.字符集]].
注意是 小写 下划线 大写 点 大写
其他写法默认无效,不提示错误,让你转圈圈去
 
然后接着讲下数据库的NLS_LANG
哈哈 就是前面多了个NLS_
我的数据库默认装的英文 外挂下中文.
所以了先看下数据库的设置
select * from v$NLS_parameters
看主要的NLS_LANGUAGE ; NLS_TERRITORY;NLS_CHARACTERSET
我的上面分别是  AMERICAN;AMERICA;AL32UTF8
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.AL32UTF8"
 
注意狗屎的细节 我们中国没有统一,所以有简体和繁体 .瞧上面 有空格是不? 就是因为这个台湾海峡在,就得上双引号.其他的语言类别就不用""...
另外注意点狗屎问题.ORACLE数据库的字符集 UTF8  不是UTF-8   注意干字.
系统变量有干 数据库则没有.
 
来点官方资料 充点门面. 狗屎的华为一天打三次电话 叫我去面试. 两个月累积下来有20次电话. 爷是专科生好不好啊 别这样玩我.知道你华为要E英文SB级.

Setting the NLS_LANG Environment Variable for Oracle Databases


Follow this procedure to set the NLS_LANG environment variable for Oracle databases.

To set the NLS_LANG environment variable for Oracle databases

  1. Determine the NLS_LANG value.
    1. In the data warehouse database, run the command

    SELECT * FROM V$NLS_PARAMETERS

    1. Make a note of the NLS_LANG value, which is in the format [NLS_LANGUAGE]_[NLS_TERRITORY].[NLS_CHARACTERSET].

      For example: American_America.UTF8

  2. For Windows:
    1. Navigate to Control Panel > System and click the Advanced tab. Click Environment Variables.
    2. In System variables section, click New.
    3. In the Variable Name field, enter NLS_LANG.
    4. In the Variable Value field, enter the NLS_LANG value that was returned in Step 1.

      The format for the NLS_LANG value should be [NLS_LANGUAGE]_[NLS_TERRITORY].[NLS_CHARACTERSET].

      For example: American_America.UTF8.

  3. For UNIX, set the variable as shown below:

    setenv NLS_LANG <NLS_LANG>

    For example: setenv NLS_LANG American_America.UTF8.

    If your data is 7-bit or 8-bit ASCII and the Informatica Server is running on UNIX, then set

    NLS_LANG <NLS_LANGUAGE>_<NLS_TERRITORY>.WE8ISO8859P1

    CAUTION:  Make sure you set the NLS_LANG variable correctly, as stated in this procedure, or your data will not display correctly.

  4. Reboot the machine after creating the variable.

                  The NLS_LANG parameter is stored in the registry under the HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\HOMEID\NLS_LANG subkey, where ID is the unique number identifying the Oracle home.

                  The NLS_LANG parameter uses the following format:

                  NLS_LANG = LANGUAGE_TERRITORY.CHARACTER_SET 

                  where:

                  Parameter Description LANGUAGESpecifies the language and conventions for displaying messages, day name, and month name.TERRITORYSpecifies the territory and conventions for calculating week and day numbers.CHARACTER_SETControls the character set used for displaying messages.
                   

                  C.2 Commonly Used Values for NLS_LANG

                  Table C-1 lists commonly used NLS_LANG values for various operating system locales:

                  Table C-1 NLS_LANG Parameter Values

                  Operating System Locale NLS_LANG Value Chinese (PRC)SIMPLIFIED CHINESE_CHINA.ZHS16GBKChinese (Taiwan)TRADITIONAL CHINESE_TAIWAN.ZHT16MSWIN950
                  English (United Kingdom)ENGLISH_UNITED KINGDOM.WE8MSWIN1252English (United States)AMERICAN_AMERICA.WE8MSWIN1252
                  French (Canada)CANADIAN FRENCH_CANADA.WE8MSWIN1252French (France)FRENCH_FRANCE.WE8MSWIN1252German (Germany)GERMAN_GERMANY.WE8MSWIN1252
                  JapaneseJAPANESE_JAPAN.JA16SJISKoreanKOREAN_KOREA.KO16MSWIN949
                  RussianRUSSIAN_CIS.CL8MSWIN1251
                0 0
                原创粉丝点击