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.