数据库的数据要更改,比如之前某字段的值都是test.php?a=a 要把test批量更换demo怎么实现呢
这时候就需要用到mysql字符串替换函数replace
mysql有什么办法批量去掉某个字段字符中的空格?不仅是字符串
前后的空格,还包含字符串中间的空格,答案是 replace,使用mysql
自
带的 replace 函数,另外还有个 trim 函数。
(1)mysql replace 函数
语法:replace(object,search,replace)
意思:把object中出现search的全部替换为replace
案例:
1 |
update `news` set `content`= replace (`content`, ' ' , '' );//清除news表中content字段中的空格 |
(2)mysql trim 函数
语法:trim([{BOTH | LEADING | TRAILING} [remstr] FROM] str)
以下举例说明:
1 |
mysql> SELECT TRIM( ' freemoban ' ); |
2 |
-> 'freemoban' |
1 |
mysql> SELECT TRIM(LEADING 'x' FROM 'xxxfreemobanxxx' ); |
2 |
-> 'freemobanxxx' |
1 |
mysql> SELECT TRIM(BOTH 'x' FROM 'xxxfreemobanxxx' ); |
2 |
-> 'freemoban' |
1 |
mysql> SELECT TRIM(TRAILING 'xyz' FROM 'freemobanxxyz' ); |
2 |
-> 'freemobanx' |
还没有人抢沙发呢~