NLS_LANG与NLS_LANGUAGE的区别

来源:互联网 发布:华为网络交换机 编辑:程序博客网 时间:2024/05/22 12:08
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设置不当会导致数据不能正常显示:

[sql] view plaincopy
  1. C:\>set nls_lang  
  2. 环境变量 nls_lang 没有定义  
  3.   
  4. C:\>sqlplus system/oracle@ora1  
  5.   
  6. SQL*Plus: Release 11.2.0.1.0 Production on 星期六 5月 12 14:27:23 2012  
  7.   
  8. Copyright (c) 1982, 2010, Oracle.  All rights reserved.  
  9.   
  10.   
  11. 连接到:  
  12. Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production  
  13. With the Partitioning, OLAP, Data Mining and Real Application Testing options  
  14.   
  15. SQL> select * from v$nls_parameters where parameter in  
  16.   2   ( 'NLS_LANGUAGE','NLS_TERRITORY','NLS_CHARACTERSET');  
  17.   
  18. PARAMETER            VALUE  
  19. -------------------- --------------------  
  20. NLS_LANGUAGE         SIMPLIFIED CHINESE  
  21. NLS_TERRITORY        CHINA  
  22. NLS_CHARACTERSET     AL32UTF8  
  23.   
  24. SQL> create table t(id number,name varchar2(20));  
  25.   
  26. 表已创建。  
  27.   
  28. SQL> insert into t values(1,'测试');  
  29.   
  30. 已创建 1 行。  
  31.   
  32. SQL> commit;  
  33.   
  34. 提交完成。  
  35.   
  36. SQL> select * from t;  
  37.   
  38.         ID NAME  
  39. ---------- ----------------------------------------  
  40.          1 测试  
  41.   
  42. SQL> exit  
  43. 从 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production  
  44. With the Partitioning, OLAP, Data Mining and Real Application Testing options 断开  
  45.   
  46. C:\>set nls_lang=.WE8ISO8859P1  
  47.   
  48. C:\>sqlplus system/oracle@ora1  
  49.   
  50. SQL*Plus: Release 11.2.0.1.0 Production on Sat May 12 14:29:27 2012  
  51.   
  52. Copyright (c) 1982, 2010, Oracle.  All rights reserved.  
  53.   
  54.   
  55. Connected to:  
  56. Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production  
  57. With the Partitioning, OLAP, Data Mining and Real Application Testing options  
  58.   
  59. SQL> select * from t;  
  60.   
  61.         ID NAME  
  62. ---------- --------------------  
  63.          1 靠  
  64.   
  65. SQL>  


REF:

1. Setting Up a Globalization Support Environment

http://docs.oracle.com/cd/E11882_01/server.112/e10729/ch3globenv.htm#NLSPG189

0 0