mysql中的去除左空格函數:
LTRIM(str) 代碼如下:
mysql> SELECT LTRIM(' barbar');
-> 'barbar'
mysql中的去除右空格函數:
代碼如下:
mysql> SELECT RTRIM('barbar ');
-> 'barbar'
trim函數可以過濾指定的字符串:
完整格式:TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str) 簡化格式:TRIM([remstr FROM] str)
以下是代碼片段:
複制代碼 代碼如下:
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'
替換數據庫中字段的最後一個分頁符
複制代碼 代碼如下:
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;
原文出處:http://www.jb51.net/article/48473.htm