PostgreSQL – ASCII Function
The ASCII
function is used to return the ASCII code value of the first character in a given string. The ASCII code is a numerical representation of a character in the ASCII character set.
The syntax of the ASCII
function is as follows:
ASCII(string)
and string
is the input string for which you want to obtain the ASCII code value of the first character.
Here’s an example of how you might use the ASCII
function in a SQL query:
SELECT ASCII('A') AS ascii_value;
In this example, the result would be the integer 65
, as the ASCII code value for the uppercase letter 'A'
is 65
.
Keep in mind that the ASCII
function only considers the first character of the input string. If you provide a longer string, only the first character will be evaluated.
If the input string is empty, the ASCII
function will return NULL
.
SELECT ASCII('') AS ascii_value;
In this case, the result would be NULL
.