UNICODE and NCHAR functions
UNICODE and NCHAR functions
UNICODE(ncharacter_expression) returns the Unicode value for the first character of the input expression.
NCHAR(integer) returns a character with the given integer Unicode value.
There are few examples.
SELECT ASCII('а' collate Cyrillic_General_CI_AS), UNICODE('а')
🚫
[[ error ]]
[[ column ]] |
---|
NULL [[ value ]] |
returns the ASCII-code value and the Unicode value of the Russian letter “а”: 224 and 1072.
SELECT CHAR(ASCII('а')), CHAR(UNICODE('а'))
🚫
[[ error ]]
[[ column ]] |
---|
NULL [[ value ]] |
Here we try to recover a symbol by its code value. We get “а” and NULL. The NULL-value returns because the 1072 code value is absent in the usual code table.
SELECT CHAR(ASCII('а')), NCHAR(UNICODE('а'))
🚫
[[ error ]]
[[ column ]] |
---|
NULL [[ value ]] |
Now it’s all right, “a” in both cases. Finally,
SELECT NCHAR(ASCII('а' collate Cyrillic_General_CI_AS))
🚫
[[ error ]]
[[ column ]] |
---|
NULL [[ value ]] |
will give “à”, because the Unicode value 224 exactly corresponds to this letter.