Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to perform muti byte to single byte conversion in DB2

53 views
Skip to first unread message

mailar

unread,
Dec 1, 2004, 3:48:00 AM12/1/04
to
HI,
Can anyone tell me how is a multi_byte to single byte and vice versa
conversion done in DB2.
It would be great even if someone can tell me how Oracle does it?
Oracle already has functions called to_single_byte and to_multi_byte
which convert a given multi byte character to single byte and vice
versa respectively.

thanks in advance
mailar

Serge Rielau

unread,
Dec 1, 2004, 8:57:34 AM12/1/04
to
Mailar,

Do you mean between GRAPHIC and CHAR or between different encodings
within CHAR (and VARCHAR)?
Also Which platform are you on? In DB2 for LUW conversion is only done
implicitly between the client and the server. Only conversion to and
from BIT data can be done explicitly using the CAST() specification.
To cast from CHAR to GRAPHIC (and back) in a Unicode database usual cast
fucntions should work. GRAPHIC and CHAR are considered equivalent in
V8, btw)
In DB2 for zOS the CAST() specification can be used to cast to and from
Unicode as well using: CAST(c_db AS VARCHAR(10) CCSID UNICODE) or
CAST(c_uni AS VARCHAR(10) CCSID ASCII)
(DB2 zOS also supports a notation with SBCS and MBCS which I'm not very
familiar with. I believe it is legacy though)

I'm not familiar enough with DB2 for iSeries, but I think you can also
use CAST() and specify the CCSID by it's integer number. DB2 for iSeries
is leading the charge in this area.

Cheers
Serge

mai...@gmail.com

unread,
Dec 2, 2004, 12:20:35 AM12/2/04
to
Hi Serge,
Thanks for your reply but actually I want this function to be used with
CHAR and VARCHAR data types.
Also, I am working on Windows(XP) platform.
The ORACLE implementation of TO_SINGLE_BYTE is something like this

Syntax
to_single_byte::=TO_SINGLE_BYTE(attribute)
Purpose
TO_SINGLE_BYTE returns attribute with all of its multibyte characters
converted
to their corresponding single-byte characters; attribute can be of data
type CHAR
or VARCHAR2. The value returned is in the same data type as attribute.
Any
multibyte characters in attribute that have no single-byte equivalents
appear in the
output as multibyte characters.
This function is useful only if your database character set contains
both single-byte
and multibyte characters.
Example
The following example illustrates going from a multibyte 'A' in UTF8 to
a single byte
ASCII 'A':
SELECT TO_SINGLE_BYTE( CHR(15711393)) FROM DUAL;
T
-
A
So, Could you tell me is ther a function or some feature in DB2 which
enables me to do this conversion.
Also, could you help me in going about the implementation of this
function in DB2.

Thanks and regards
mailar

Serge Rielau

unread,
Dec 2, 2004, 8:47:09 AM12/2/04
to
I have to confess ignorance.
To the best of my knowledge there is no matching function in DB2 for LUW.

Cheers
Serge

0 new messages