(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)
簡化格式:TRIM([remstr FROM] str)
以下舉例說明:
代碼如下 復制代碼1 mysql> SELECT TRIM(' phpernote ');
2 -> 'phpernote'
1 mysql> SELECT TRIM(LEADING 'x' FROM 'xxxphpernotexxx');
2 -> 'phpernotexxx'
1 mysql> SELECT TRIM(BOTH 'x' FROM 'xxxphpernotexxx');
2 -> 'phpernote'
1 mysql> SELECT TRIM(TRAILING 'xyz' FROM 'phpernotexxyz');
mysql中的去除左空格函數:
以下是代碼片段:
代碼如下 復制代碼mysql> SELECT LTRIM(' barbar');
-> 'barbar'
This function is multi-byte safe.
mysql中的去除右空格函數:
RTRIM(str)
Returns the string str with trailing space characters removed.
以下是代碼片段:
mysql> SELECT RTRIM('barbar ');
-> 'barbar'
This function is multi-byte safe.