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 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
Suppose we have 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)
登錄后復(fù)制
現(xiàn)在,以下查詢將使用LTRIM()和RTRIM()函數(shù)一次性從名稱中刪除前導(dǎo)和尾隨空格 −
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)
登錄后復(fù)制
以上就是如何使用 MySQL LTRIM() 和 RTRIM() 函數(shù)同時(shí)刪除字符串中的前導(dǎo)空格和尾隨空格?的詳細(xì)內(nèi)容,更多請關(guān)注www.92cms.cn其它相關(guān)文章!