Select*fromstudent;+------+---------+---------+-------- ---+|Id |Name |Address|Subject |+------+---"/> Select*fromstudent;+------+---------+---------+-------- ---+|Id |Name |Address|Subject |+------+---">

Home  >  Article  >  Database  >  How can we use ASCII() function with MySQL WHERE clause?

How can we use ASCII() function with MySQL WHERE clause?

WBOY
WBOYforward
2023-08-25 21:09:02709browse

我们如何将 ASCII() 函数与 MySQL WHERE 子句一起使用?

When you use the ASCII() function with a WHERE clause, the output it returns will depend on the conditions given in the WHERE clause. For example, let's say we have a table called "Students" and we want to get the numeric code greater than 65 for the first character of a student's name. A query for this can be written as follows -

mysql> Select * from student;
+------+---------+---------+-----------+
| Id   | Name    | Address | Subject   |
+------+---------+---------+-----------+
| 1    | Gaurav  | Delhi   | Computers |
| 2    | Aarav   | Mumbai  | History   |
| 15   | Harshit | Delhi   | Commerce  |
| 20   | Gaurav  | Jaipur  | Computers |
+------+---------+---------+-----------+
4 rows in set (0.10 sec)

mysql> Select Name, ASCII(Name) As 'ASCII VALUE OF 1st Character' From Student WHERE ASCII(Name)>65;
+---------+------------------------------+
| Name    | ASCII VALUE OF 1st Character |
+---------+------------------------------+
| Gaurav  |         71                   |
| Harshit |         72                   |
| Gaurav  |         71                   |
+---------+------------------------------+
3 rows in set (0.00 sec)

The above is the detailed content of How can we use ASCII() function with MySQL WHERE clause?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete