views:

32

answers:

1

Hello,

I have a column in my database table which has lows of text and lows of rows. In the text, a url needs to be changed for every row. In each row the url can exist more than once.

Can I use the replace function to change all the urls in the text field in my database table without affecting the rest of the text in that same column?

Thanks

+1  A: 

Use REPLACE()

UPDATE table SET text = REPLACE(text, 'from', 'to')

Make precise from: like with http://url_from.com/ to http://url_to.com/

cichy
I doubt all urls are the same
Col. Shrapnel
How would I change that query if the column with the string is col1, and I want to change the string 'hello' to 'bye'?
oshirowanen
If not all are same, than he can use 3rd party functions to regex_replace:http://www.php-groupies.de/blogs/archives/17-Regular-Expression-Functions-for-MySQL.html
cichy
UPDATE table SET col1 = REPLACE(col1, 'hello', 'bye')make dump of the table, and test your query till you get proper result ;)
cichy
Worked perfectly. Thanks
oshirowanen
Yes, i have a test server onto which I replicate the website daily, so any testing it done on the test server before moving onto the live server.
oshirowanen
@oshirowanen if you have all these links the same, you should not store them in the database at all
Col. Shrapnel