Powerful mysql trim () Functions

Source: Internet
Author: User

Remove left space in mysql:
LTRIM (str)
Returns the string str with leading space characters removed.

The following is a code snippet:

Copy codeThe Code is as follows:
Mysql> select ltrim ('barbar ');
-> 'Barbar'


This function is multi-byte safe.

Remove right spaces in mysql:
RTRIM (str)
Returns the string str with trailing space characters removed.

The following is a code snippet:

Copy codeThe Code is as follows:
Mysql> select rtrim ('barbar ');
-> 'Barbar'


This function is multi-byte safe.

The trim function can filter specified strings:
Complete 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 snippet:

Copy codeThe Code is as follows:
Mysql> select trim ('bar'); // spaces before and after deletion by default
-> 'Bar'
Mysql> select trim (LEADING ', 'from', barxxx'); // Delete the specified first character, such ','
-> 'Barxxx'
Mysql> select trim (BOTH ', 'from', bar,'); // deletes the specified start and end characters.
-> 'Bar'
Mysql> select trim (TRAILING ',' FROM 'barxxyz ,,');
-> 'Barxxyz'


Copy codeThe Code is as follows:
Mysql> UPDATE table SET 'field' = TRIM (TRAILING ', 'From 'field') WHERE 'field' LIKE '% ,';


This function is multi-byte safe.

Replace the last paging character of the field in the database

Copy codeThe Code is 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;

Related Article

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.