ASCII and CHAR functions
ASCII and CHAR functions
Let’s start from two reciprocally related functions - ASCII and CHAR.
The ASCII function returns an ASCII code value of the leftmost character of a character expression, being a function argument.
Here is an example of the way to determine how many different letters which the names of the ships in the Ships table start from are:
SELECT COUNT(DISTINCT ASCII(name))
FROM Ships
🚫
[[ error ]]
[[ column ]] |
---|
NULL [[ value ]] |
The result is 11. To find out what these letters are, we can use CHAR function that returns a character by a known ASCII code value (from 0 to 255):
SELECT DISTINCT CHAR(ASCII(name))
FROM Ships
ORDER BY 1
🚫
[[ error ]]
[[ column ]] |
---|
NULL [[ value ]] |
We should note that the identical result can be got simpler using one more function - LEFT.