admin 管理员组

文章数量: 887021

NLS

1. 主要区别:

NLS_LANG是环境变量,包括3部分NLS参数:NLS_LANGUAGE, NLS_TERRITORY, NLS_CHARACTERSET,需要在启动SQLPLUS等工具之前设置;

NLS_LANGUAGE主要控制SESSION中提示消息的语言,可以使用ALTER SESSION在SQLPLUS里面设置;

NLS_TERRITORY主要控制SESSION中的日期和货币等本地化参数的现实格式,也可以像NLS_LANGUAGE一样在 SESSION 里面设置;

NLS_CHARACTERSET控制客户端的字符集,不能在SESSION里面进行设置,只能通过NLS_LANG环境变量的方式进行设置。



2. 设置方法:

2.1 环境变量设置(windows),下划线必须和territory配对,点必须和字符集配对

set nls_lang=american_america.utf8

set nls_lang=american / set nls_lang=american_ / set nls_lang=american_.

set nls_lang=_america

set nls_lang=.utf8


2.2 SESSION设置

alter session set nls_language='american' nls_territory='america';

alter session set nls_language='american';

alter session set nls_territory='america';



3. 注意事项:

NLS_CHARACTERSET设置不当会导致数据不能正常显示:

C:\>set nls_lang
环境变量 nls_lang 没有定义C:\>sqlplus system/oracle@ora1SQL*Plus: Release 11.2.0.1.0 Production on 星期六 5月 12 14:27:23 2012Copyright (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 optionsSQL> select * from v$nls_parameters where parameter in2   ( 'NLS_LANGUAGE','NLS_TERRITORY','NLS_CHARACTERSET');PARAMETER            VALUE
-------------------- --------------------
NLS_LANGUAGE         SIMPLIFIED CHINESE
NLS_TERRITORY        CHINA
NLS_CHARACTERSET     AL32UTF8SQL> create table t(id number,name varchar2(20));表已创建。SQL> insert into t values(1,'测试');已创建 1 行。SQL> commit;提交完成。SQL> select * from t;ID NAME
---------- ----------------------------------------1 测试SQL> exit
从 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options 断开C:\>set nls_lang=.WE8ISO8859P1C:\>sqlplus system/oracle@ora1SQL*Plus: Release 11.2.0.1.0 Production on Sat May 12 14:29:27 2012Copyright (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 optionsSQL> select * from t;ID NAME
---------- --------------------1 靠SQL>


REF:

1. Setting Up a Globalization Support Environment

.112/e10729/ch3globenv.htm#NLSPG189

本文标签: NLS