The ASCII() function returns the ASCII code of the first character in a given string or character value. If the input string contains more than one character, only the first character is evaluated.
MySQL ASCII Function Syntax
SQL
x
1
ASCII(character);
MySQL ASCII Function Example
This query returns the ASCII value of the first character in the first_name column from the Patients table.
SQL
1
1
SELECT ASCII(first_name) AS NumCodeOfFirstChar
2
FROM Patients;
Note: The
ASCII()
function is supported in MySQL but not in SQLite. This example does not work in the TechKubo playground.
MySQL ASCII Function Parameter
Parameter | Description |
---|---|
character | The input string or character. Only the first character is evaluated. |
MySQL ASCII Function Notes:
- If multiple characters are provided, only the first is used.
- If the input is
NULL
, the result isNULL
.- Supported starting with MySQL 4.0.