To remove the left space function in MySQL:
LTRIM (str)
Returns the string str with leading space characters removed.
The following is a code fragment:
Copy Code code as follows:
mysql> SELECT LTRIM (' Barbar ');
-> ' Barbar '
This function is multi-byte safe.
Removal of the right space function in MySQL:
RTRIM (str)
Returns the string str with trailing space characters removed.
The following is a code fragment:
Copy Code code as follows:
mysql> SELECT RTRIM (' Barbar ');
-> ' Barbar '
This function is multi-byte safe.
The TRIM function can filter the specified string:
Full format: TRIM ([{BOTH | Leading | Trailing} [REMSTR] from] str)
Simplified format: TRIM ([remstr from] str)
Returns the string str with all remstr prefixes or suffixes removed. If none of the specifiers BOTH, leading, or trailing is given, BOTH is assumed. Remstr is optional and, if not specified, spaces are removed.
The following is a code fragment:
Copy Code code as follows:
mysql> SELECT TRIM (' Bar '); Default delete before and after spaces
-> ' Bar '
Mysql> SELECT TRIM (leading ', ' from ', barxxx '); Deletes the specified first character Furu ', '
-> ' barxxx '
Mysql> SELECT TRIM (BOTH ', ' from ', bar,,,, '); Delete the specified end character
-> ' Bar '
Mysql> SELECT TRIM (trailing ', ' from ' barxxyz,, ');
-> ' barxxyz '
Copy Code code as follows:
mysql> UPDATE table SET ' field ' =trim (trailing ', ' from ' field ') where where ' field ' like '%, ';
This function is multi-byte safe.
replace the last page break in a field in a database
Copy Code code as follows:
UPDATE [!db.pre!] Ecms_news_data_1 SET ' Newstext ' =trim (trailing ' [!--empirenews.page--] ' from ' newstext ') WHERE id=585;
SELECT TRIM (trailing ' [!--empirenews.page--] ' from ' Newstext ') as Newstex from [!db.pre!] Ecms_news_data_1 WHERE id=585;