You can specify hexadecimal literals (or even binary literals ) with 0x , x'' or x'' :
select 0xC2A2; select x'C2A2'; select X'C2A2';
But know that the return type is a binary string, so every byte is considered a character. You can check this with char_length :
select char_length(0xC2A2)
2
If you want instead of UTF-8 , you need to use convert :
select convert(0xC2A2 using utf8mb4)
And we can see that C2 A2 is considered 1 character in UTF-8:
select char_length(convert(0xC2A2 using utf8mb4))
1
In addition, you do not need to worry about invalid bytes, because convert will automatically delete them:
select char_length(convert(0xC1A2 using utf8mb4))
0
As you can see, pin 0 , because C1 A2 is an invalid UTF-8 byte sequence.
Pacerier
source share