SelectName,TRIM(Name)AS'NameWithoutSpaces'fromtest_trim;+---------------+------------------ ---+|Name&"/> SelectName,TRIM(Name)AS'NameWithoutSpaces'fromtest_trim;+---------------+------------------ ---+|Name&">

Home  >  Article  >  Database  >  How to remove both leading and trailing spaces from a string without using MySQL LTRIM() and RTRIM() functions?

How to remove both leading and trailing spaces from a string without using MySQL LTRIM() and RTRIM() functions?

WBOY
WBOYforward
2023-08-28 13:35:181523browse

如何在不使用 MySQL LTRIM() 和 RTRIM() 函数的情况下同时从字符串中删除前导空格和尾随空格?

In addition to the LTRIM() and RTRIM() functions, MySQL also has the TRIM() function, which removes both leading and trailing functions from a string. The usage of TRIM() function can be understood from the following example of test_trim table whose "Name" column contains names with leading and trailing spaces.

Example

mysql> Select Name, TRIM(Name)AS 'Name Without Spaces' from test_trim;
+---------------+---------------------+
| Name          | Name Without Spaces |
+---------------+---------------------+
| Gaurav        | Gaurav              |
| Rahul         | Rahul               |
| Aarav         | Aarav               |
+---------------+---------------------+
3 rows in set (0.00 sec)

The above is the detailed content of How to remove both leading and trailing spaces from a string without using MySQL LTRIM() and RTRIM() functions?. 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