I have the following rows:
Name Url
name1 http://foo.com/this/that
name6 http://that.net/hello
name2 http://foo.com/hello/world
name3 http://foo.com/world/hello
name4 http://hello.com/this/that
I need to write a query that will change every foo.com
to hello.com
.
Any ideas?
replace() Parameters The replace() method can take maximum of 3 parameters: old - old substring you want to replace. new - new substring which will replace the old substring. count (optional) - the number of times you want to replace the old substring with the new substring.
The substring() method extracts characters, between two indices (positions), from a string, and returns the substring. The substring() method extracts characters from start to end (exclusive). The substring() method does not change the original string.
One of the simplest and straightforward methods of replacing a substring is using the replace, replaceAll or replaceFirst of a String class.
UPDATE <table name> SET Url = REPLACE (Url, "foo.com" , "hello.com")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With