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