MySQL Erase string space method in database

Source: Internet
Author: User
Tags rtrim trim

(1) MySQL replace function

Syntax: replace (object,search,replace)

Replaces all occurrences of search in object with replace

Case:

The code is as follows Copy Code

1 Update ' News ' Set ' content ' =replace (' content ', ', ', ');


Clear the spaces in the content field in the news table


(2) MySQL trim function

Full format: TRIM ([{BOTH | Leading | Trailing} [REMSTR] from] str)
Simplified format: TRIM ([remstr from] str)

The following examples illustrate:

The code is as follows Copy Code

1 mysql> SELECT TRIM (' phpernote ');

2-> ' Phpernote '

1 mysql> SELECT TRIM (leading ' x ' from ' xxxphpernotexxx ');

2-> ' phpernotexxx '

1 mysql> SELECT TRIM (BOTH ' x ' from ' xxxphpernotexxx ');

2-> ' Phpernote '

1 mysql> SELECT TRIM (trailing ' xyz ' from ' phpernotexxyz ');


To remove the left space function in MySQL:

The code is as follows Copy Code
LTRIM (str)
Returns the string str with leading space characters removed.

The following is a code fragment:

  code is as follows copy code

mysql> SELECT LTRIM (' Barbar ');
-> ' Barbar '

This function is multi-byte safe.

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

The following code fragment:
mysql> SELECT RTRIM (' barbar   ');
-> ' barbar '
This function is Multi-Byte safe.

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.