The ASCII() function in MySQL returns the numeric value of the leftmost character in a given string. This numeric value corresponds to the ASCII code of the character.
Syntax:
ASCII(string)
Parameters:
- string: The input string whose leftmost character's ASCII value is to be returned.
Returns:
- The ASCII code of the first character in the string.
- If the string is empty, it returns 0.
- If the input is
NULL, it returnsNULL.
Examples:
-
Basic Example:
SELECT ASCII('A');Output:
65(ASCII code ofA). -
Multiple Characters:
SELECT ASCII('Hello');Output:
72(ASCII code ofH, the leftmost character). -
Empty String:
SELECT ASCII('');Output:
0 -
Numeric Input as String:
SELECT ASCII('123');Output:
49(ASCII code of1). -
Special Characters:
SELECT ASCII('!');Output:
33(ASCII code of!). -
NULL Input:
SELECT ASCII(NULL);Output:
NULL
Use Cases:
- Determining ASCII values for data manipulation or transformation.
- Encoding or decoding purposes.
- String comparison or analysis at the character level.
Let me know if you need more detailed examples or explanations!
No comments:
Post a Comment