Mysql method to remove spaces: 1. Use the replace() function to remove spaces in characters, the syntax is "replace(object,' ','')"; 2. Use the trim() function to remove the left and right characters spaces, the syntax is "trim('object')".
The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.
How to remove spaces in mysql
(1)mysql replace function
Syntax: replace(object,search,replace)
Meaning: Replace all occurrences of search in object with replace
Case:
Original data:
Repair statement:
update t_user_score set cname = REPLACE(cname ,' ','') ;
After repair:
(2) mysql trim function
Syntax:
Full format : TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str)
Simplified format: TRIM([remstr FROM] str)
Returns the string str, in which all remstr prefixes and/or suffixes have been removed. If none of the classifiers BOTH, LEADIN or TRAILING is given, BOTH is assumed. remstr is optional and can remove spaces if not specified.
Recommended learning: mysql video tutorial
The above is the detailed content of How to remove spaces in mysql. For more information, please follow other related articles on the PHP Chinese website!