Home  >  Article  >  Database  >  How to use the TRIM() function in MySQL

How to use the TRIM() function in MySQL

WBOY
WBOYforward
2023-05-26 13:02:153461browse

TRIM()

TRIM([remstr FROM] str)The function is used to return the substring after deleting all remstr strings on both sides of the string str. Remstr defaults to spaces. For example:

SELECT TRIM('  MySQL字符串函数  ') AS str1,
       TRIM('-' FROM '--MySQL字符串函数--') AS str2;
str1          |str2          |
--------------+--------------+
MySQL字符串函数|MySQL字符串函数|

TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str) function is used to return all remstr on both sides/left/right of the deleted string str The substring after the string, the strings on both sides (BOTH) are deleted by default, and remstr defaults to spaces. For example:

SELECT TRIM(LEADING ' ' FROM '  MySQL字符串函数  ') AS str1,
       TRIM(TRAILING '-' FROM '--MySQL字符串函数--') AS str2;
str1            |str2            |
----------------+----------------+
MySQL字符串函数  |--MySQL字符串函数|

The above is the detailed content of How to use the TRIM() function in MySQL. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete