mysql trim函数用法的小例子

发布时间:2019-10-10编辑:脚本学堂
本文介绍了mysql中trim函数的用法,分享一个mysql trim函数的例子,trim函数去除左右空格,有需要的朋友参考下。

mysql trim函数:
TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str) , TRIM(remstr FROM] str)
Returns the string str with all remstr prefixes and/or suffixes removed. If none of the specifiers BOTH, LEADING, or TRAILING is given, BOTH is assumed. If remstr is optional and not specified, spaces are removed.

例子,trim函数去除空格。
 

复制代码 代码示例:
mysql> SELECT TRIM(' bar ');
-> 'bar'
mysql> SELECT TRIM(LEADING 'x' FROM 'xxxbarxxx');
-> 'barxxx'
mysql> SELECT TRIM(BOTH 'x' FROM 'xxxbarxxx');
-> 'bar'
mysql> SELECT TRIM(TRAILING 'xyz' FROM 'barxxyz');
-> 'barx'