当 CHAR_LENGTH() 或 CHARACTER_LENGTH() 字符串函数与 WHERE 子句一起使用时,其返回的输出将取决于 WHERE 子句中给出的条件。例如,假设我们有一个名为“Student”的表,并且我们只想获取那些字符数小于 6 的姓名,那么我们可以编写以下查询 -
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, CHAR_LENGTH(Name) from student WHERE CHAR_LENGTH(Name)<6; +-------+-------------------+ | Name | CHAR_LENGTH(Name) | +-------+-------------------+ | Aarav | 5 | +-------+-------------------+ 1 row in set (0.00 sec)
以上是我们如何将 CHAR_LENGTH() 函数与 MySQL WHERE 子句一起使用?的详细内容。更多信息请关注PHP中文网其他相关文章!