Link to home
Start Free TrialLog in
Avatar of regzero
regzero

asked on

How to read Unicode data in Oracle?

Hi,

Does anyone know how to read Unicode data in Oracle database and write onto a text file? Because when I read it, some Unicode charaters change to "¿".

My code is:

void CMyDlg::ReadUnicode()
{
   _RecordsetPtr recordset = NULL;
   _CommandPtr command = NULL;
    _variant_t vRowsAffected;
    _variant_t vNull;
    vNull.vt = VT_ERROR;
    vNull.scode = DISP_E_PARAMNOTFOUND;
    HRESULT hr;
    hr = recordset.CreateInstance(__uuidof(Recordset));
    hr = command.CreateInstance(__uuidof(Command));

    command->ActiveConnection = GetConnection();
    command->CommandType      = adCmdText;
    command->CommandText      = "SELECT TEXT FROM UNICODE WHERE ID=1";

    recordset = command->Execute(&vRowsAffected, &vNull, adCmdText);

    if (recordset!=NULL)
    {
      recordset->MoveFirst();
      while (!recordset->adoEOF)
      {
             _variant_t vcode = recordset->Fields->GetItem(L"TEXT")->GetValue();
          recordset->MoveNext();
      }
    }
    recordset->Close();
    command->Release();
}

I have a string "đăng" stored in Oracle database and it displays in memory when I view it: "00142BBC  BF 00 BF 00 6E 00 67  ¿.¿.n.g".

Please help,
Thanks
Avatar of migel
migel

Hi!
It seems like you put no UNICODE string into the database - Your data looks like you make it by
WCHAR* wch = L"uung";
where 'u' char is the locale specific char (not ASCII 127).
Can you fisrtly put proper unicode string into the base and test?
To make unicode string use MultiByteToWideChar API
Avatar of regzero

ASKER

I insert value from web using JSP. I set request.setCharacterEncoding("UTF-8").

For unicode characters with 0x00XX, e.g: "ê"->0x00EA, value is OK.
Ex, I have a string like this "lê lá là" in DB, and on the memory it shows:
001422E4  6C 00 EA 00 20 00 6C  l.ê. .l
001422EB  00 E1 00 20 00 6C 00  .á. .l.
001422F2  E0 00 00 00 00 00 02  à......

but with unicode value like 0xXXXX, e.g: "ạ"->0x1EA1, it's wrong. It converts value to "¿" ->0x00BF.
Avatar of regzero

ASKER

:) It's OK now, I solved it
Hi!
Can you place here your solution ???? just for learning?
Avatar of regzero

ASKER

Hi Migel,
I didn't know you posted.

I found the document in Oracle page, it's all here:

http://otn.oracle.com/products/oracle8i/htdocs/OTN_ODBC_Unicode_cabaird.htm

Dang
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial