切换 ORACLE 客户端字符集
如果我们需要连接不同的数据库,而这些数据库又有不同的字符集,在登录 plsql developer 时会有提示:
Database characterset (AL32UTF8) and Client character set (ZHS16GBK) are different.
Character setconversion may cause unexpected results.
Note: you can set theclient character set through the NLS_LANG environment variable or the NLS_LANGregistry key in
HKEY_LOCAL_MACHINE\SOFTWARE\Oracle\KEY_OraClient11g_home1
好像环境变量的优先级要高于注册表。
当然,环境变量实际上也是注册表,即:
HKLM\SYSTEM\CurrentControlSet\Control\SessionManager\Environment
@echo off
for /f"tokens=1* delims= " %%1 in('reg query "HKLM\SYSTEM\CurrentControlSet\Control\SessionManager\Environment" /v NLS_LANG^|findstr /i "REG_SZ" ') do setcharset=%%~1
if"%charset%"=="NLS_LANG REG_SZ SIMPLIFIED CHINESE_CHINA.ZHS16GBK" (
echo %charset%
reg ADD"HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"/v NLS_LANG /t REG_SZ /d "SIMPLIFIED CHINESE_CHINA.AL32UTF8" /f
) ELSE (
echo %charset%
reg ADD"HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"/v NLS_LANG /t REG_SZ /d "SIMPLIFIED CHINESE_CHINA.ZHS16GBK" /f
)
这只是示例,最终要以服务器上的字符集为准。
原文链接:https://www.f2er.com/oracle/211137.html