mysql强大的trim()函数

所有的人都想停留在那山顶,但是所有的乐趣和成长都是发生在往上爬的过程中。新的一天,早安!
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;

以上就是mysql强大的trim()函数。许多找借口的人,在享受了借口带来的短暂快乐后,起初有点自责,多多少少有点骗人的味道。可是重复的次数一多,也就变得无所谓了,原本有点良知的心变得麻木不仁。其实,正是借口绊住了前进的脚步,迷惑了原本聪慧的头脑,让成功离你而去。更多关于mysql强大的trim()函数请关注haodaima.com其它相关文章!

标签: mysql trim