mysql中的去除左空格函數:
LTRIM(str)
Returns the string str with leading space characters removed.
以下是代碼片段:
復制代碼 代碼如下:
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.
trim函數可以過濾指定的字符串:
完整格式:TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str)
簡化格式:TRIM([remstr FROM] str)
Returns the string str with all remstr prefixes or suffixes removed. If none of the specifiers BOTH, LEADING, or TRAILING is given, BOTH is assumed. remstr is optional and, if not specified, spaces are removed.
以下是代碼片段:
復制代碼 代碼如下:
mysql> SELECT TRIM(' bar '); //默認刪除前後空格
-> 'bar'
mysql> SELECT TRIM(LEADING ',' FROM ',,barxxx'); //刪除指定首字符 如',‘
-> 'barxxx'
mysql> SELECT TRIM(BOTH ',' FROM ',,bar,,,'); //刪除指定首尾字符
-> 'bar'
mysql> SELECT TRIM(TRAILING ',' FROM 'barxxyz,,');
-> 'barxxyz'
復制代碼 代碼如下:
mysql> UPDATE table SET `field`=TRIM(TRAILING ',' FROM `FIELD`) WHERE WHERE `FIELD` LIKE '%,';
This function is multi-byte safe.
替換數據庫中字段的最後一個分頁符
復制代碼 代碼如下:
UPDATE [!db.pre!]ecms_news_data_1 SET `newstext`=TRIM(TRAILING '[!--empirenews.page--]' FROM `newstext`) WHERE id=585;
SELECT TRIM(TRAILING '[!--empirenews.page--]' FROM `newstext`) AS newstex FROM [!db.pre!]ecms_news_data_1 WHERE id=585;