教程集 www.jiaochengji.com
教程集 >  数据库  >  mysql  >  正文 mysql trim函数用法举例

mysql trim函数用法举例

发布时间:2016-05-03   编辑:jiaochengji.com
本文介绍了mysql trim函数的用法,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.

例3:
 

复制代码 代码示例:
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 trim函数的例子:
 

复制代码 代码示例:

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.

您可能感兴趣的文章:
mysql trim函数用法的小例子
mysql怎么去除字段中换行符与回车符
mysql trim函数用法举例
MYSQL语句去除字段空格
mysql trim函数用法实例
mysql删除字段为Null或空格数据
mysql查询字段中带空格的值的sql语句
php中trim函数使用注意事项
mysql trim()函数用法实例
mysql清除数据库中字符串空格方法

关键词: trim函数   
[关闭]
~ ~