NLS_LANG与NLS_LANGUAGE的区别

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设置不当会导致数据不能正常显示:

  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>  
C:\>set nls_lang
环境变量 nls_lang 没有定义

C:\>sqlplus system/oracle@ora1

SQL*Plus: Release 11.2.0.1.0 Production on 星期六 5月 12 14:27:23 2012

Copyright (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 options

SQL> select * from v$nls_parameters where parameter in
  2   ( 'NLS_LANGUAGE','NLS_TERRITORY','NLS_CHARACTERSET');

PARAMETER            VALUE
-------------------- --------------------
NLS_LANGUAGE         SIMPLIFIED CHINESE
NLS_TERRITORY        CHINA
NLS_CHARACTERSET     AL32UTF8

SQL> 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=.WE8ISO8859P1

C:\>sqlplus system/oracle@ora1

SQL*Plus: Release 11.2.0.1.0 Production on Sat May 12 14:29:27 2012

Copyright (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 options

SQL> select * from t;

        ID NAME
---------- --------------------
         1 靠

SQL>


REF:

1. Setting Up a Globalization Support Environment

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
"failed to get local nls_lang"是一个错误信息,通常在使用数据库或运行某些程序时出现。这个错误信息通常表示系统无法获取本地的"NLS_LANG"(National Language Support)设置。 "NLS_LANG"是一个环境变量,用于指定数据库和程序的字符集。它决定了如何在系统中处理不同语言和字符编码。当系统无法获取本地"NLS_LANG"设置时,会出现"failed to get local nls_lang"错误。 解决此错误的方法是按照以下步骤操作: 1. 检查系统环境变量设置:确保"NLS_LANG"环境变量已正确设置。您可以在操作系统的环境变量设置中查看或编辑此设置。确保"NLS_LANG"的值与您需要的字符集匹配。 2. 检查数据库配置:如果您在使用数据库时遇到此错误,请确保数据库配置文件中的"NLS_LANG"参数正确设置。您可能需要联系数据库管理员或查看数据库相关文档来进行正确配置。 3. 检查程序设置:如果此错误是在运行某个程序时出现的,请检查程序的配置文件或代码中是否有"NLS_LANG"设置。将其设置为正确的值。 4. 重新启动系统:在进行上述更改后,重新启动系统以确保环境变量和配置生效。 需要注意的是,对于不同的操作系统和应用程序,解决此错误的具体步骤可能会有所不同。您可以参考相关的操作系统和应用程序文档来获取更详细的解决方案。 总之,"failed to get local nls_lang"错误表示系统无法获取本地的"NLS_LANG"设置,通过正确设置环境变量和配置,可以解决此问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值