Home > Database > Mysql Tutorial > body text

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

王林
Release: 2023-09-12 09:17:06
forward
860 people have browsed it

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)
Copy after login

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)
Copy after login

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)
Copy after login

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)
Copy after login

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!

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