Home  >  Article  >  Database  >  mysql中删除字符串或字段中空格函数

mysql中删除字符串或字段中空格函数

WBOY
WBOYOriginal
2016-06-07 17:51:441270browse

在mysql中提供了ltrim,rtrim函数来删除字符的首毛空格那么如果我要删除字符如\"abc fdsa\"应该如何做来,下面我们来看教程

ltrim 函数

 代码如下 复制代码
> concat('.', ltrim(' ddd '), '.'); 

rtrim函数

 代码如下 复制代码
mysql> select concat('.', rtrim(' ddd '), '.'); 

trim 字符串函数,实在是强大。它不仅能消除字符串首尾部的空格,还可以消除我们指定的任意字符。ltrim(), rtrim() 只是它的一个功能子集。

 

 代码如下 复制代码
UPDATE `tran`
SET `status` = '1'
WHERE trim( replace( `msg`, 'rn', ' ' ) ) = '我爱你';

数据中的回车换行等替换成空格之后再trim掉,就达到目的了,虽然不是特别完美,但是由于没办法在用户录入的时候控制,所以只能出此下策,好在MySQL内置函数的效率还是很有保证的

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn