简体   繁体   English

10g和11g差异中的Oracle Unicode支持

[英]Oracle Unicode Support in 10g and 11g Differences

I am running into a problem that I have not yet been able to explain. 我遇到了一个我无法解释的问题。 I have code that takes a number, gets the national character code for the number using NCHR, and then performs a RAWTOHEX conversion on it. 我有接受数字的代码,使用NCHR获取该数字的国家字符代码,然后对其执行RAWTOHEX转换。

It worked in 10g for years. 它在10g中工作了好几年。 When we upgraded to 11g it started returning different values. 当我们升级到11g时,它开始返回不同的值。 I boiled it all down to a few statements, and created a demonstration script: 我将其归纳为几句话,并创建了一个演示脚本:

SET SERVEROUTPUT ON;
DECLARE
  rawVar RAW(2000);
  nVar NVARCHAR2(1000);
BEGIN
  nVar :=  NCHR(1112);
  SELECT RAWTOHEX(nVar) INTO rawVar FROM DUAL;
  DBMS_OUTPUT.PUT_LINE('rawVar: ' || rawVar);
END;
/

When executed in 10g, the ouptut is "0458". 当以10g执行时,输出为“ 0458”。 In 11g (from the same computer and using the same Oracle client software) the output is "00040058". 在11g中(从同一台计算机使用相同的Oracle客户端软件),输出为“ 00040058”。 The upstream process that relies on the output is expecting "0458". 依赖于输出的上游过程预期为“ 0458”。

Interestingly (to me), if I change the definition of nVar to be an VARCHAR2 instead of an NVARCHAR2, I get "0458" as the output on 11g. 有趣的是(对我而言),如果我将nVar的定义更改为VARCHAR2而不是NVARCHAR2,则在11g上将得到“ 0458”作为输出。

Can someone please help to explain why the results are different? 有人可以帮忙解释一下为什么结果不同吗? I have searched Oracle's release notes and support system, but have not found any answers. 我已经搜索了Oracle的发行说明和支持系统,但是没有找到任何答案。

Many thanks in advance. 提前谢谢了。

This is a horrible bug in Oracle 11 Change 这是Oracle 11 Change中的一个可怕的错误

nVar :=  NCHR(1112); 

to

nVar :=  CHR(1112 using nchar_cs);

and things will work again. 事情将会再次发生。 These expressions should be identical, according to Oracle docs. 根据Oracle文档,这些表达式应该相同。 In Oracle 10 this is true, but not in 11. 在Oracle 10中确实如此,但在11中却不是。

Are the two databases using the same character set ? 两个数据库是否使用相同的字符集?

Could you run this query in both instances: 您能否在两个实例中都运行此查询:

select value 
  from nls_database_parameters 
 where parameter='NLS_NCHAR_CHARACTERSET';

CHR and NCHR functions will only give the same result if the databases have the same character set. 仅当数据库具有相同的字符集时,CHR和NCHR函数才会给出相同的结果。

RAWTOHEX returns a character value, but you are selecting it into a RAW, so there will be some implicit conversion there. RAWTOHEX返回一个字符值,但是您将其选择为RAW,因此在那里会有一些隐式转换。 Then you are trying to use DBMS_OUTPUT which will need to implicitly convert that RAW variable into a string. 然后,您尝试使用DBMS_OUTPUT,这将需要将该RAW变量隐式转换为字符串。

Potentially you can deal with a RAW value (ie bytes) or a Character value (text which may get converted/translated depending on character set / language settings) or a hex representation of the bytes in the the string. 潜在地,您可以处理RAW值(即字节)或Character值(根据字符集/语言设置可能会转换/翻译的文本)或字符串中字节的十六进制表示形式。 Which of those do you have in the database, and which do you want to return to the application ? 您在数据库中有哪些,并且想返回到应用程序? Then just do that ONE conversion and do it explicitly. 然后,只需执行一次ONE转换并明确进行即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM