MySQL powerful trim () function _mysql

Source: Internet
Author: User
Tags rtrim trim
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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.