首頁 >資料庫 >mysql教程 >如何使用 MySQL LTRIM() 和 RTRIM() 函數同時刪除字串中的前導空格和尾隨空格?

如何使用 MySQL LTRIM() 和 RTRIM() 函數同時刪除字串中的前導空格和尾隨空格?

王林
王林轉載
2023-08-27 15:25:021116瀏覽

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

For removing both leading and trailing spaces at once from a string by using LTRIM() and RTRIM() functions, we must have to use one function as an argument for other function. In other function. In other function. In other function. In other function. In other function. In other function. In other function. In other function。 other words, we must have to pass either LTRIM() function as an argument of RTIM() function or vice versa. It can be understood from the following example −

Example

#we#wet#wevv a table 'test_trim' having a column 'Name' containing the values with leading and trailing spaces both −

mysql> Select * from test_trim;
+---------------+
| Name          |
+---------------+
| Gaurav        |
| Rahul         |
| Aarav         |
+---------------+
3 rows in set (0.00 sec)

現在,以下查詢將使用LTRIM()和RTRIM()函數一次從名稱中刪除前導和尾隨空格−

mysql> Select Name, LTRIM(RTRIM(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)

mysql> Select Name, RTRIM(LTRIM(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)

以上是如何使用 MySQL LTRIM() 和 RTRIM() 函數同時刪除字串中的前導空格和尾隨空格?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除