mysql批量清除字符串空格的方法
mysql有什么办法批量去掉某个字段字符中的空格?不仅是字符串前后的空格,还包含字符串中间的空格,答案是 replace,使用mysql自带的 replace 函数,另外还有个 trim 函数。
(1)mysql replace 函数
语法:replace(object,search,replace)
意思:把object中出现search的全部替换为replace
案例:
1update `news` set `content`=replace(`content`,' ','');//清除news表中content字段中的空格
(2)mysql trim 函数
语法:trim([{BOTH | LEADING | TRAILING} [remstr] FROM] str)
举例:
1mysql> SELECT TRIM(' phpernote ');
2-> 'phpernote'
3mysql> SELECT TRIM(LEADING 'x' FROM 'xxxphpernotexxx');
4-> 'phpernotexxx'
5mysql> SELECT TRIM(BOTH 'x' FROM 'xxxphpernotexxx');
6-> 'phpernote'
7mysql> SELECT TRIM(TRAILING 'xyz' FROM 'phpernotexxyz');
8-> 'phpernotex'
捐赠本站(Donate)
如您感觉文章有用,可扫码捐赠本站!(If the article useful, you can scan the QR code to donate))
- Author: shisekong
- Link: https://blog.361way.com/mysql-replace-trim/2527.html
- License: This work is under a 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议. Kindly fulfill the requirements of the aforementioned License when adapting or creating a derivative of this work.