oracle 如何检查客户端的 NLS_LANG?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11522800/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I check the NLS_LANG of the client?
提问by Rafael Piccolo
I'm working on Windows OS, I know that this setting is stored in the registry. The problem is that the registry path changes from version to version, browsing though that bunch of registry keys is definitly not a good idea.
我正在使用 Windows 操作系统,我知道此设置存储在注册表中。问题是注册表路径会随着版本的不同而变化,浏览那一堆注册表项绝对不是一个好主意。
I can get the NLS_LANG
of the server with SELECT USERENV ('language') FROM DUAL
.
我可以NLS_LANG
使用SELECT USERENV ('language') FROM DUAL
.
I'd like to compare that with the client setting and show a warning when they don't match, just like Pl/Sql Developer does.
我想将它与客户端设置进行比较,并在它们不匹配时显示警告,就像 Pl/Sql Developer 一样。
采纳答案by Jér?me
According to Jocke's answer (thanks Jocke), I tested the following query:
根据 Jocke 的回答(感谢 Jocke),我测试了以下查询:
SELECT DISTINCT client_charset FROM v$session_connect_info
WHERE sid = sys_context('USERENV','SID');
It perfectly does the job, but I'm unsure if any user will have the necessary rights.
它完美地完成了这项工作,但我不确定是否有任何用户将拥有必要的权限。
回答by Bjarte Brandt
This is what I do when I troubleshoot encoding-issues. (The NLS_LANG value read by sqlplus):
这就是我在解决编码问题时所做的。(sqlplus读取的NLS_LANG值):
SQL>/* It's a hack. I don't know why it works. But it does!*/
SQL>@[%NLS_LANG%]
SP2-0310: unable to open file "[NORWEGIAN_NORWAY.WE8MSWIN1252]"
You willhave to extract the NLS_LANG value in current ORACLE_HOME from the registry. All client-side tools (sqlplus, sqlldr, exp, imp, oci, etc...) read this value from registry and determine if any character transcoding should occur.
你将不得不提取从注册表当前ORACLE_HOME的NLS_LANG值。所有客户端工具(sqlplus、sqlldr、exp、imp、oci 等)都从注册表中读取此值并确定是否应发生任何字符转码。
ORACLE_HOME and registry section:
ORACLE_HOME 和注册表部分:
C:\>dir /s/b oracle.key
C:\Oracle10\BIN\oracle.key
C:\>type C:\Oracle10\BIN\oracle.key
SOFTWARE\ORACLE\KEY_OraClient10204_Home
In times like these I turn to IPython to demonstrate an idea:
在这样的时候,我求助于 IPython 来展示一个想法:
A couple of lookups and you are there!
几个查找,你就在那里!
In [36]: OHOMES_INSTALLED = !where oci.dll
In [37]: OHOMES_INSTALLED
Out[37]:
['C:\Oracle10\BIN\oci.dll',
'C:\oraclexe\app\oracle\product\11.2.0\server\bin\oci.dll']
In [38]: ORACLE_HOME = os.path.dirname(OHOMES_INSTALLED[0])
In [39]: ORACLE_HOME
Out[39]: 'C:\Oracle10\BIN'
In [40]: f = open(os.path.join(ORACLE_HOME, "oracle.key"))
In [41]: SECTION = f.read()
In [42]: SECTION
Out[42]: 'SOFTWARE\ORACLE\KEY_OraClient10204_Home\n'
In [43]: from _winreg import *
In [44]: aReg = ConnectRegistry(None,HKEY_LOCAL_MACHINE)
In [46]: aKey = OpenKey(aReg,SECTION.strip())
In [47]: val = QueryValueEx(aKey, "NLS_LANG")
In [48]: print val
(u'NORWEGIAN_NORWAY.WE8MSWIN1252', 1)
回答by Jocke
I am not sure if this works every time but for me in sql*plus:
我不确定这是否每次都有效,但对我来说在 sql*plus 中:
variable n varchar2(200)
execute sys.dbms_system.get_env('NLS_LANG', :n )
print n
AMERICAN_AMERICA.WE8ISO8859P1
Just build a function-wrapper, grant execute to the users who needs it, and there you go.
只需构建一个函数包装器,将 execute 授予需要它的用户,然后就可以了。