當 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中文網其他相關文章!