Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PL/SQL Chinese garbled in oracle

My oracle version is 11g,installing on linux. Client is xp.

Now,By PL/SQL to query data and the chinese grabled; like this(Field Name): enter image description here

In pl/sql execute command:" select userenv('language') from dual;" and show

SIMPLIFIED CHINESE_CHINA.AL32UTF8(I think it is Server-side character set)

So I look at the Windows xp registry: HKEY_LOCAL_MACHINE->SOFTWARE->Oracle->NLS_LANG. It show:

SIMPLIFIED CHINESE_CHINA.ZHS16GBK (I think it is Client-side character set)

I changed it to

SIMPLIFIED CHINESE_CHINA.AL32UTF8

But the Chinese are still garbled.

And,This "NAME" field should actually show : "北京市".

I execute command:

select dump(name,1016) from MN_C11_SM_S31 where objectid=1;

and show:enter image description here

Does that mean that the data itself is stored is incorrect? How should I do?

Supplementary:Just,I used C# code to parse this string by UTF-8:"e58c97e4baace5b882".

and it show: "北京市".I think this proves the data itself is not wrong.

like image 518
yeguo Avatar asked Nov 12 '22 19:11

yeguo


1 Answers

You need to be careful.
SQLplus and OracleSqlDeveloper might actually display Chinese characters incorrectly.
And you need to take an nvarchar (utf8) field for a chinese string.

Try using a C# Windows application to input, insert and display data, it uses unicode internally, so you can at least rule out that bug source. Don't use a console application for display, console applications can't display Unicode characters correctly.

Then, you need to store your string in an nvarchar field (not varchar), and use a parameter of type nvarchar, when you insert your string.

INSERT INTO YOUR_TABLE (newname)
VALUES (:UnicodeString)

command.Parameters.Add (":UnicodeString", OracleType.NVarChar).Value = stringToSave;
like image 90
Stefan Steiger Avatar answered Nov 15 '22 06:11

Stefan Steiger