网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 服务器与数据库 > MySQL
User Name
Password
 
FAQ Members List Calendar Cheap Glasses Mark Forums Read

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   IP: 49.87.41.166
Old 2015-03-05, 09:34 AM
Agra Agra is offline
初级会员
 
Join Date: 2007-01-09
Posts: 2
Agra 现在声名狼藉
Default mysql清除数据库中字符串空格方法

在mysql清除字符串空格有两个常用的使用方法一种是利用trim函数另一种是直接replace字符替换函数进行清除,下面我来给大家详细介绍。
(1)mysql replace 函数

语法:replace(object,search,replace)

意思:把object中出现search的全部替换为replace

案例:

Code:
update `news` set `content`=replace(`content`,' ','');
//清除news表中content字段中的空格


(2)mysql trim 函数

完整格式:TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str)
简化格式:TRIM([remstr FROM] str)

以下举例说明:

Code:
 1 mysql> SELECT TRIM(' phpernote  '); 

2 -> 'phpernote'

1 mysql> SELECT TRIM(LEADING 'x' FROM 'xxxphpernotexxx'); 

2 -> 'phpernotexxx'

1 mysql> SELECT TRIM(BOTH 'x' FROM 'xxxphpernotexxx'); 

2 -> 'phpernote'

1 mysql> SELECT TRIM(TRAILING 'xyz' FROM 'phpernotexxyz');
mysql中的去除左空格函数:
Code:
LTRIM(str) 
 Returns the string str with leading space characters removed.
以下是代码片段:
Code:
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.
Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 03:06 AM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.