Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

nchar to string_to_raw to utf8

user12070046Mar 26 2014 — edited Mar 27 2014

Is there a way to get from nchar to raw utf8 encoding? Seems like utl_i18n.string_to_raw should do it but its not producing the expected results

select utl_i18n.raw_to_nchar('E382B9', 'utf8') raw_as_utf16,

       utl_i18n.string_to_raw(utl_i18n.raw_to_nchar('E382B9', 'utf8'), 'utf8') utf16_as_raw

from dual;

RAW_AS_UTF16 UTF16_AS_RAW

------------ ------------

ス            C2BF

I would expect utf16_as_raw to be E382B9, but instead it looks like unknown character

Oracle 11.2.0.3

NLS_NCHAR_CHARACTERSET AL16UTF16

NLS_CHARACTERSET WE8MSWIN1252

Message was edited by: user12070046

looking at the specs for utl_i18n, string_to_raw is not overloaded to accept nvarchar2 parameter. Only this:

FUNCTION string_to_raw(data IN VARCHAR2 CHARACTER SET ANY_CS,                         

                                     dst_charset IN VARCHAR2 DEFAULT NULL)                          

                                     RETURN RAW;


So, it appears that any nvarchar2 data provided to that function will get converted to varchar2, and in my case will result in some unknown characters due to config of charset and nls_charset. Looks like string_to_raw won't work.


I'd like to find a way to take nvarchar2 data and convert to raw encoded as utf8. There's a way to do the opposite and get raw to nvarchar2 using utl_i18n.raw_to_nchar('E382B9', 'utf8'), but I can't find a way to get nvarchar2 back to raw.

This post has been answered by Sergiusz Wolicki-Oracle on Mar 27 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 24 2014
Added on Mar 26 2014
2 comments
1,858 views