Oracle SQL Developer 客户端编码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20422930/
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
Oracle SQL Developer client encoding
提问by maestro
I read many of the related stackoverflow topics and I spent a whole day with googleing the following problem but I haven't found anything that would help, however the problem not seems to be complecated.
我阅读了许多相关的 stackoverflow 主题,并花了一整天的时间在 google 上搜索以下问题,但我没有找到任何有用的东西,但是问题似乎并不复杂。
I have an Oracle database. Let's see the following PL/SQL script:
我有一个 Oracle 数据库。让我们看看下面的 PL/SQL 脚本:
CREATE TABLE Dummy(
id number(19,0),
tclob clob,
tnclob nclob,
PRIMARY KEY (id));
INSERT INTO dummy (id, tclob, tnclob) VALUES (1, '?$?¤*>;''<'', '?$?¤*>;''<'');
SELECT tclob, tnclob FROM dummy;
My problem is that '?' and ''' characters are stored as a question mark. I also tried to load the previously inserted values through JAVA, but I get the question marks instead of the special characters.
我的问题是“?” 和 ''' 字符存储为问号。我也尝试通过 JAVA 加载之前插入的值,但我得到的是问号而不是特殊字符。
I created a small JAVA method which uses OraclePreparedStatement to save test data, and I use setNString() method to attach the nclob data to the query. In this case all characters are displayed fine in JAVA and also in SqlDeveloper.
我创建了一个使用 OraclePreparedStatement 保存测试数据的小型 JAVA 方法,并使用 setNString() 方法将 nclob 数据附加到查询中。在这种情况下,所有字符都可以在 JAVA 和 SqlDeveloper 中正常显示。
So a possible solution is to use JAVA to save my data into the db. I have a thousands of lines SQL script which inserts data and I don't necesseraly want to write the whole thing again in java.
所以一个可能的解决方案是使用 JAVA 将我的数据保存到数据库中。我有数千行插入数据的 SQL 脚本,我不想在 Java 中再次编写整个内容。
So the question is: why the sqldeveloper breaks the special characters?
那么问题来了:为什么sqldeveloper会破坏特殊字符?
My settings:
我的设置:
SELECT DECODE(parameter, 'NLS_CHARACTERSET', 'CHARACTER SET',
'NLS_LANGUAGE', 'LANGUAGE',
'NLS_TERRITORY', 'TERRITORY') name,
value from v$nls_parameters
WHERE parameter IN ( 'NLS_CHARACTERSET', 'NLS_LANGUAGE', 'NLS_TERRITORY')
Result:
结果:
NAME VALUE
------------- -------------
LANGUAGE HUNGARIAN
TERRITORY HUNGARY
CHARACTER SET EE8ISO8859P2
I changed SqlDeveloper/Preferences/Environment/Encoding to UTF-8. I also changed HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_OraDb11g_home1 value to HUNGARIAN_HUNGARY.UTF8
我将 SqlDeveloper/Preferences/Environment/Encoding 更改为 UTF-8。我还将 HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_OraDb11g_home1 值更改为 HUNGARIAN_HUNGARY.UTF8
Update:I tried to insert the data with the following syntaxes:
更新:我尝试使用以下语法插入数据:
INSERT INTO dummy (id, tclob, tnclob) VALUES (1, N'?$?¤*>;''<'', N'?$?¤*>;''<'');
INSERT INTO dummy (id, tclob, tnclob) VALUES (1, '?$?¤*>;''<'', to_nclob('?$?¤*>;''<''));
Nothing helped.
没有任何帮助。
So what can I do?
那我能做什么?
回答by Mohsen Heydari
On the PC that PLSQL is installed, set the value of NLS_LANG
registery entry equal to the PC's operation system locale (code page)
, equivalent value.
How to detect operating system language locale?
How to map OS locale to NLS_LANG value?
在安装了 PLSQL 的 PC 上,将NLS_LANG
registery 条目的值设置为 PC 的operation system locale (code page)
等效值。
如何检测操作系统语言区域设置?
如何将操作系统语言环境映射到 NLS_LANG 值?
When using PLSQL the initial parameter of client-language that is required to create an Oracle session is read from NLS_LANG registry entry.
Due to Oracle documents, invalid data usually occurs in a database because the NLS_LANG parameter is not set properly on the client.
The NLS_LANG value should reflect the client operating system code page.
For example, in an English Windows environment, the code page is WE8MSWIN1252. When the NLS_LANG parameter is set properly, the database can automatically convertincoming data from the client operating system to its encoding.
When using JAVA method, the client-language parameter is set by the value from the Control Panel, under Regional and Language Options, so the things will be OK.
使用 PLSQL 时,创建 Oracle 会话所需的客户端语言的初始参数是从 NLS_LANG 注册表项中读取的。
由于 Oracle 文档的原因,数据库中通常会出现无效数据,因为客户端上的 NLS_LANG 参数设置不正确。NLS_LANG 值应反映客户端操作系统代码页。
例如,在英文 Windows 环境中,代码页为 WE8MSWIN1252。当 NLS_LANG 参数设置正确时,数据库可以自动将来自客户端操作系统的传入数据转换为其编码。
使用JAVA方法时,client-language参数由控制面板中的值设置,在Regional和Language选项下,所以一切都会好的。