ASCII, Ord function usage in MySQL

Source: Internet
Author: User
Tags ord

One, ASCII (STR1)

Returns the ASCII code value of the leftmost character of the string str. If Str is an empty string, returns 0. If STR is NULL, return null

Example:
1.

The code is as follows Copy Code
Mysql> Select ASCII (' Hi ');
+ ————-+
| ASCII (' Hi ') |
+ ————-+
| 104 |
+ ————-+
1 row in Set

104 is the ASCII value of H

2. ASCII values for output B and B

The code is as follows Copy Code

Mysql> SELECT ASCII (' B ') as Lower_case, ASCII (' B ') as upper_case;
+ ———— + ———— +
| Lower_case | Upper_case |
+ ———— + ———— +
|         98 | 66 |
+ ———— + ———— +
1 row in Set

3. Using the ASCII function in the WHERE statement

Output Aut_name The ASCII value of the first letter is less than 70 data

The code is as follows Copy Code
SELECT Aut_name,ascii (Aut_name) as "ASCII value of 1st character"
From author
WHERE ASCII (aut_name) <70;

4. There is no data in the output field that does not have an ASCII value

The code is as follows Copy Code

SELECT * FROM table_name WHERE not Column_to_check REGEXP ' [a-za-z0-9.,-] ';

5. Use a computed string with substring the second subsequent ASCII value

The code is as follows Copy Code

Mysql> Select ASCII (SUBSTRING (' database ', 2, 1));
+ ———————————-+
| ASCII (SUBSTRING (' database ', 2, 1)) |
+ ———————————-+
| 97 |
+ ———————————-+
1 row in Set

Second, Ord function

ORD (str)

If the string str leftmost character is a multibyte character, it is passed in a format

The code is as follows Copy Code

((*256+ (second byte ASCII code)) [*256+third byte ASCII code ...]

Returns the ASCII code value of the character to return the multibyte character code. If the leftmost character is not a multibyte character. Returns the same value returned with the ASCII () function.

  code is as follows copy code


1 MySQL > select ORD (' 2 ');

2            ->

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.