Skip to content

ASCII

Returns the ASCII code for the first character of a string expr.

Syntax

sql
ASCII(expr)

Arguments

expr: Input string.

Return Values

Numeric representation of the ASCII character.

Usage Notes

  • If expr is empty, the return value is NULL.
  • If expr is NULL, the return value is also NULL.
  • If expr is numeric, an attempt is made to convert the value to a character data type and then process it.

Examples

sql
select ascii('abc') as result1,
 ascii('*bc') as result2, 
 ascii(NULL) as result3, 
 ascii(567) as result4,
 ascii('567') as result5 
;
+---------+---------+---------+---------+---------+
| RESULT1 | RESULT2 | RESULT3 | RESULT4 | RESULT5 |
+---------+---------+---------+---------+---------+
| 97      | 42      | NULL    | 53      | 53      |
+---------+---------+---------+---------+---------+