In mysql, the ASCII function converts characters into ascii code values. the following small series will introduce the usage and examples of ASCII functions in mysql to coders. For more information about coders, see. ASCII (str1)
Returns the ASCII code value of the leftmost character of the str string. If str is a null string, 0 is returned. If 'str' is NULL, return NULL
Example:
1.
mysql> select ascii('hi');+————-+| ascii('hi') |+————-+| 104 |+————-+1 row in set
104 is the ASCII value of h
2. output ASCII values of B and B
mysql> SELECT ASCII('b')AS Lower_Case, ASCII('B') AS Upper_Case;+————+————+| Lower_Case | Upper_Case |+————+————+| 98 | 66 |+————+————+1 row in set
3. use ASCII functions in the where statement
Output data whose ASCII value is less than 70 at the beginning of aut_name
SELECT aut_name,ASCII(aut_name)as "ASCII value of 1st character" FROM author WHERE ASCII(aut_name)<70;
4. the output field does not contain any data without ASCII values.
SELECT * FROM table_name WHERE NOT column_to_check REGEXP '[A-Za-z0-9.,-]';
5. use it with SUBSTRING to calculate the second ASCII value after the string
mysql> select ASCII(SUBSTRING('database',2,1));+———————————-+| ASCII(SUBSTRING('database',2,1)) |+———————————-+| 97 |+———————————-+1 row in set