Mysql batch clearing string Spaces

Source: Internet
Author: User

Is there any way for mysql to remove spaces in characters in a field in batches? It is not only a space before and after the string, but also a space in the middle of the string. The answer is replace. Use the replace function that comes with mysql. There is also a trim function.

(1) mysql replace Function

Syntax: replace (object, search, replace)

Replace all search objects with replace

Case:

Update 'news 'set 'content' = replace ('content', '',''); // clear spaces in the content field of the news table.

(2) mysql trim Function

Syntax: trim ([{BOTH | LEADING | TRAILING} [remstr] FROM] str)

The following is an example:

mysql> SELECT TRIM(' phpernote  ');-> 'phpernote'
mysql> SELECT TRIM(LEADING 'x' FROM 'xxxphpernotexxx');-> 'phpernotexxx'
mysql> SELECT TRIM(BOTH 'x' FROM 'xxxphpernotexxx');-> 'phpernote'
mysql> SELECT TRIM(TRAILING 'xyz' FROM 'phpernotexxyz');-> 'phpernotex'
Articles you may be interested in
  • Summary of the JavaScript method for removing string Spaces
  • MySQL replace function replacement string statement usage
  • PHP compresses html webpage code to reduce the amount of network data transmitted, clear spaces, tabs, and comment mark
  • Note the following when querying strings with single quotes and inserting strings with single quotes in Mysql:
  • How does php clear html format, remove spaces in text, and intercept text?
  • Php merges consecutive spaces in strings
  • PHP compresses html webpage code (clear spaces, line breaks, tabs, comment tags)
  • MySQL string truncation Function

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.