How to find sub-string and replace it?
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
n开发者_JAVA技巧ame4 http://hello.com/this/that
I need to write a query that will change every foo.com
to hello.com
.
Any ideas?
UPDATE <table name> SET Url = REPLACE (Url, "foo.com" , "hello.com")
Take a look at the REPLACE() function: http://msdn.microsoft.com/en-us/library/ms186862.aspx. You should be able to use that in an UPDATE statement to achieve the desired result.
Check out the replace function:
update table set url = replace(url, 'foo.com', 'hello.com')
UPDATE table
SET Url = REPLACE(url, 'foo.com', 'hello.com')
UPDATE table
SET Url = REPLACE(url, 'http://foo.com/', 'http://hello.com/')
it's safer!!
精彩评论