What can MySQL do to remove spaces from a field character in bulk? Not only the space before and after the string, but also the space in the middle of the string, the answer is replace, using the MySQL self-contained replace function, plus a trim function.
(1) MySQL replace functionSyntax: replace (object,search,replace) meaning: Replace all occurrences of search in object with the Replace case:SQL Code copy content to clipboard
- Update ' News ' set ' content ' =replace (' content ',' ', ');//clear spaces in the content field in the news table
(2) MySQL trim functionSyntax: Trim ([{BOTH | Leading | TRAILING} [REMSTR] from] str) The following examples illustrate:SQL Code copy content to clipboard
- Mysql> SELECT TRIM (' phpernote ');
- ' Phpernote '
SQL Code copy content to clipboard
- Mysql> SELECT TRIM (Leading ' x ' from ' xxxphpernotexxx ');
- ' phpernotexxx '
SQL Code copy content to clipboard
- Mysql> SELECT TRIM (BOTH ' x ' from ' xxxphpernotexxx ');
- ' Phpernote '
SQL Code copy content to clipboard
- Mysql> SELECT TRIM (TRAILING ' xyz ' from ' phpernotexxyz ');
- ' Phpernotex '
Reprint: http://www.itokit.com/2012/1221/74847.html
The MySQL command statement to get rid of the field's hollow lattice characters