如何在 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)
广告