Select*fromStudent;+------+-- -------+----------+-----------+|Id |Name |Address|Su"/> Select*fromStudent;+------+-- -------+----------+-----------+|Id |Name |Address|Su">

Home  >  Article  >  Database  >  How can we use CHAR_LENGTH() function with MySQL WHERE clause?

How can we use CHAR_LENGTH() function with MySQL WHERE clause?

PHPz
PHPzforward
2023-08-27 12:37:02879browse

我们如何将 CHAR_LENGTH() 函数与 MySQL WHERE 子句一起使用?

When the CHAR_LENGTH() or CHARACTER_LENGTH() string function is used with a WHERE clause, the output it returns will depend on the conditions given in the WHERE clause. For example, let's say we have a table called "Student" and we want to get only those names with less than 6 characters, then we can write the following query -

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)

The above is the detailed content of How can we use CHAR_LENGTH() function with MySQL WHERE clause?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete