The MySQLASCII () function returns the ASCII value of a character.

Source: Internet
Author: User
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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.