Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
|
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 27th, 2004, 03:50 PM
Authorized User
 
Join Date: Mar 2004
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default Replace text fragments

Hello!

Is there a way to replace specific text fragment (string) with another one in all fields of a table by an SQL query?

Thanks!
Janis

 
Old October 29th, 2004, 01:43 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Do you want that to be done for a column on all rows or for all columns in all rows? Can you explain that in detail?

_________________________
- Vijay G
Strive for Perfection
 
Old October 29th, 2004, 07:21 PM
Authorized User
 
Join Date: Mar 2004
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by happygv
 Do you want that to be done for a column on all rows or for all columns in all rows? Can you explain that in detail?
For one (text type) column on all rows.

Janis

 
Old October 30th, 2004, 01:24 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Check the MySql documentation for, if that supports REPLACE() function, if so you can do that easily. Else, will have to look for other way round.

_________________________
- Vijay G
Strive for Perfection
 
Old November 1st, 2004, 09:23 AM
Authorized User
 
Join Date: Mar 2004
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks! It really worked, when I found that function.

Before that I searched for "replace" in the documentation, but found that replace is an operation like insert, only it replaces the rows in case of a duplicate key or something like that. And I didn't even search more to find out that there is such a function replace(). :)

So, I successfully managed to replace text with this kind of query:

update tableName
set fieldName=replace(fieldName,"oldString","newString")

Thanks,
Janis

 
Old November 1st, 2004, 04:43 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Yes, Glad that it worked. I was sure about Replace function's existence in MS Sql Server, though I haven't really used that in MySql/need didn't arise yet. That's why I suggested to check if MySql supports that function.

Cheers!

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
Search and Replace a text in XML file AyatKh XML 17 May 23rd, 2012 09:05 PM
replace text without using regex mrame XSLT 7 July 28th, 2008 09:12 AM
Text Replace with XSLT pendyalap XSLT 13 October 1st, 2006 05:51 PM
Replace textboxes or textareas with some text amit_bhatia Beginning PHP 1 December 7th, 2004 11:32 AM
Button to replace close window text Burton HTML Code Clinic 12 November 6th, 2003 12:27 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.