CLOB + Russina text

CLOB + Russina text

Postby lak-b » Thu 08 Apr 2010 07:50

Hello. I want to pass in stored procedure CLOB with russian text.

Code: Select all
                var encoding = new System.Text.ASCIIEncoding();
                OracleLob oracleLob = new OracleLob(OracleDbType.Clob);
                var arrData = encoding.GetBytes(pData); // pData contains XML with russian letters
                oracleLob.Write(arrData, 0, arrData.Length);
                ...


All of russian letters converts to '?' character in Oracle. What should I do? Change encoding (I try UTF-8/16 and Unicode but no luck)? Anything else?
lak-b
 
Posts: 1
Joined: Thu 08 Apr 2010 07:42

Postby StanislavK » Fri 09 Apr 2010 16:27

Please note that CLOB contains a sequence of bytes from the encoded string. Thus, under debug you see these bytes, not the string itself in the CLOB value. To retrieve the string from CLOB you should get a byte array and then decode it, as it is shown in the following sample:
Code: Select all
// Set encoding to Unicode.
var encoding = new System.Text.UnicodeEncoding();
OracleLob oracleLob = new OracleLob(OracleDbType.Clob);

// Encode the string.
var arrData = encoding.GetBytes(pData);

// Check that string can be decoded properly.
string s = new string(encoding.GetChars(arrData));
Console.WriteLine(s);

// Populate CLOB.
oracleLob.Write(arrData, 0, arrData.Length);

// Retrieve the string from CLOB, check that it is decoded properly.
oracleLob.Read(arrData, 0, arrData.Length);
s = new string(encoding.GetChars(arrData));
Console.WriteLine(s);

Feel free to contact us if something is unclear.
StanislavK
Devart Team
 
Posts: 1710
Joined: Thu 03 Dec 2009 10:48


Return to dotConnect for Oracle