如何使用 MySQL WHERE 子句的 ASCII() 函数?
虽然在 WHERE 子句中使用 ASCII() 函数,但通过该子句返回的输出将取决于 WHERE 子句中给出的条件。例如,假设我们有一个名为“Student”的表,并且我们希望获取学生名前面的第一个字符的数字(大于 65)。此查询可以写成如下形式——
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)
广告