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

Reply
 
Thread Tools Display Modes
  #1   IP: 204.45.15.210
Old 2015-12-19, 11:04 PM
Omaha Omaha is offline
初级会员
 
Join Date: 2011-02-05
Posts: 1
Omaha 现在声名狼藉
Default Mysql search and replace some text in a field

What Mysql query will do a text search and replace in one particular field in a table?

ie search for 'children eyeglasses' and replace with 'kids glasses' so a record with a field with the value : 'How to buy children eyeglasses online?' becomes: 'How to buy kids glasses online?'.
Reply With Quote
  #2   IP: 204.45.15.210
Old 2015-12-19, 11:10 PM
Purchase Purchase is offline
初级会员
 
Join Date: 2010-05-31
Posts: 1
Purchase 现在声名狼藉
Default

Change table_name and field to match your table name and field in question:
Code:
UPDATE table_name SET field = REPLACE(field, 'children eyeglasses', 'kids glasses') WHERE INSTR(field, 'children eyeglasses') > 0;

INSTR (ori_str, sub_str):
ori_str The string to be searched.
sub_str The string to be searched for within the ori_str

MySQL INSTR() takes a string and a substring of it as arguments, and returns an integer which indicates the position of the first occurrence of the substring within the string.
Reply With Quote
Reply


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Find and Replace Text in MySQL Database using SQL topvip MySQL 0 2012-07-10 08:12 AM
htaccess 301 redirect tutorial yahoo 服务器环境搭建 0 2009-09-06 12:45 AM

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


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