I’m trying to generate characters in different encodings using MySQL.
My script looks like this:
SET @id := 678;
SELECT
@id,
CHAR(@id USING utf32),
CHAR(@id USING utf16),
CHAR(@id USING utf8),
HEX(CHAR(@id USING utf32)),
HEX(CHAR(@id USING utf16)),
HEX(CHAR(@id USING utf8))
My expected result is:
678
ʦ
ʦ
ʦ
000002A6
02A6
CAA6
What i actually get:
678
ʦ
ʦ
<-- Questionable
000002A6
02A6
02 <-- Questionable
Is there a way to do this in MySQL?
Answere
Thanks at lanzz.
SET @id = 45678;
SELECT
@id,
CHAR(@id USING utf32),
CONVERT(CHAR(@id USING utf32) USING utf16),
CONVERT(CHAR(@id USING utf32) USING utf8),
HEX(CHAR(@id USING utf32)),
HEX(CONVERT(CHAR(@id USING utf32) USING utf16)),
HEX(CONVERT(CHAR(@id USING utf32) USING utf8));
Result:
45678
뉮
뉮
뉮
0000B26E
B26E
EB89AE
Try
CONVERT(CHAR(678 USING UTF16) USING UTF8). TheCHAR()call will convert your unicode character code into an actual string, andCONVERT()will convert that string into actual UTF8.