网络营销电子商务研究中心  
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

Reply
 
Thread Tools Display Modes
  #1   IP: 153.99.40.156
Old 2015-04-20, 02:31 PM
Paintersville Paintersville is offline
初级会员
 
Join Date: 2012-11-11
Posts: 3
Paintersville 现在声名狼藉
Default mysql命令语句来去除掉字段中空格字符的方法

mysql有什么办法批量去掉某个字段字符中的空格?不仅是字符串前后的空格,还包含字符串中间的空格,答案是 replace,使用mysql自带的 replace 函数,另外还有个 trim 函数。

(1)mysql replace 函数

语法:replace(object,search,replace)

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

案例:

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



(2)mysql trim 函数

语法:trim([{BOTH | LEADING | TRAILING} [remstr] FROM] str)


以下举例说明:


SQL Code复制内容到剪贴板

mysql> SELECT TRIM(' phpernote ');
-> 'phpernote'


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


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


mysql> SELECT TRIM(TRAILING 'xyz' FROM 'phpernotexxyz');
-> 'phpernotex'
Reply With Quote
Reply


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

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:46 AM.


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