Home >Database >Mysql Tutorial >How are the MySQL LTRIM() and RTRIM() functions used with the WHERE clause?

How are the MySQL LTRIM() and RTRIM() functions used with the WHERE clause?

王林
王林forward
2023-09-12 09:17:06879browse

MySQL LTRIM() 和 RTRIM() 函数如何与 WHERE 子句一起使用?

The MySQL LTRIM() and RTRIM() functions can be used to eliminate leading and trailing spaces from column values ​​in a table. These functions work fine even if we apply conditions in WHERE clause.

Example

mysql> Select LTRIM(Name) from Student;
+-------------+
| LTRIM(Name) |
+-------------+
| Gaurav      |
| Aarav       |
| Harshit     |
| Gaurav      |
| Yashraj     |
+-------------+
5 rows in set (0.13 sec)

The above query removes leading space characters from the value of the "Name" column.

mysql> Select RTRIM(Name) from Student;
+-------------+
| RTRIM(Name) |
+-------------+
| Gaurav      |
| Aarav       |
| Harshit     |
| Gaurav      |
| Yashraj     |
+-------------+
5 rows in set (0.00 sec)

The above query removes trailing space characters from the value of the "Name" column.

mysql> Select LTRIM(Name) from Student Where Name = 'Harshit';
+-------------+
| LTRIM(Name) |
+-------------+
| Harshit     |
+-------------+
1 row in set (0.05 sec)

The above query removes leading space characters from the value i.e. the value given in the WHERE clause "Harshit" of the "Name" column.

mysql> Select RTRIM(Name) from Student Where Name = 'Gaurav';
+-------------+
| RTRIM(Name) |
+-------------+
| Gaurav      |
| Gaurav      |
+-------------+
2 rows in set (0.00 sec)

The above query removes trailing space characters from the value i.e. the value given in the WHERE clause "Gaurav" of the "Name" column.

The above is the detailed content of How are the MySQL LTRIM() and RTRIM() functions used with the 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