在将ASCII()
函数与WHERE子句一起使用时,其返回的输出将取决于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)