设置NLS_LANG的作用
- 将NLS_LANG设置为与Oracle数据库字符集相同的参数,可以跳过在不同字符集之间的代码转换处理步骤。
- NLS_LANG参数的目的,是让Oracle数据库知道客户端的字符集设置,所以,NLS_LANG的设置要与客户端操作系统使用的字符集保持一致。
以下摘自《NLS_LANG Explained (How does Client-Server Character Conversion Work?) (Doc ID 158577.1)》:
-
NLS_LANG is used to let Oracle know what characterset you client’s OS is USING so that Oracle can do (if needed) conversion from the client’s characterset to the database characterset.
-
Using for the the
part of NLS_LANG the same value as the NLS_CHARACTERSET MAY be correct but IS NOT ALWAYS correct. Please DO NOT assume that NLS_LANG needs to be ALWAYS the same as the database characterset. THIS IS NOT TRUE. The used NLS_LANG value has as such no relation with the NLS_CHARACTERSET. If they happen to be the same, fine but they are simply 2 different things. See point 4.1.1 and 4.1.2 -
The characterset defined with the NLS_LANG parameter does NOT CHANGE your client’s characterset, it is used to let Oracle know what characterset you are USING on the client side, so Oracle can do the proper conversion. You cannot change the characterset of your client by using a different NLS_LANG! To change the client characterset you need to change the OS configuration, not a Oracle parameters.
-
Another myth is that if you don’t set the NLS_LANG on the client it uses the NLS_LANG of the server. This is also NOT true!
-
If the NLS_LANG is the same as the database characterset then Oracle OCI currently (for performance reasons) will do NO validation of the codes passed through against the configured characterset.