MySQL ASCII Function | Return ASCII Value of First Character

MySQL ASCII is an inbuilt function in MySQL. It returns the ASCII value of the first character of the input string to it. In this article, we will discuss the MySQL ASCII Function. Also, we will discuss a few examples of using it.

Syntax

ASCII (string)

Parameters

The MySQL ASCII Function expects only one parameter. A string is input to the function.

Return Value

The function returns the integer ASCII value of the first character of the string input to it. However, if the string is empty, the function returns 0.

MySQL ASCII Function

Examples

Let’s discuss a few examples of using the function.

Example 1: Single Characters

For instance, consider single characters as input.

mysql> SELECT ASCII('a') as lowercase, ASCII('A') as uppercase;
+-----------+-----------+
| lowercase | uppercase |
+-----------+-----------+
|        97 |        65 |
+-----------+-----------+

In the above example, the function returns the ASCII values of ‘a’ and ‘A’ respectively.

Example 2: Input String

Similarly, for a string input, the function returns the ASCII value of the first character of the string.

mysql> SELECT ASCII('Concatly') as asciivalue;
+------------+
| asciivalue |
+------------+
|         67 |
+------------+

In the above example, the function returns the ASCII value of ‘C’.

Example 3: Empty String

However, if the input string is empty, the function returns 0.

mysql> SELECT ASCII('') as asciivalue;
+------------+
| asciivalue |
+------------+
|          0 |
+------------+

Conclusion

In conclusion, we discussed the MySQL ASCII Function in this article. You can read more about it on the Official MySQL Documentation. Additionally, you can learn about more MySQL String Functions on Concatly.

Spread the Knowledge

Leave a Reply

Your email address will not be published. Required fields are marked *