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

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

PHPz
Release: 2023-08-27 12:37:02
forward
883 people have browsed it

我们如何将 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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template