Have a MySQL database table with 2 columns: id, url
The url column has values like 'http://www.example.com/'.
I need to add a string like 'http://www.x.com?redirect=' to the beginning of all the column values - ie to change the values like this: http://www.example.com/ ===> http://www.x.com?redirect=http://www.example.com/
Anyone has some clues to how I can do that?
I have looked into using CONCAT(), but so far I haven't been able to make it work :(
Thanks a lot for your help, Louisa
Yes, you use can use CONCAT
:
SELECT CONCAT('http://www.x.com?redirect=', url) AS url
FROM yourtable
See it working online: sqlfiddle
使用concat会像这样:
update table set url=concat('http://www.x.com?redirect=',url);
You can do this:
Update myTable
SET data= (SELECT CASE WHEN data IS NULL THEN '' ELSE data END AS data WHERE id = 1) + 'some text'
WHERE id = 1
field = field + value does not work when field is null.
Take a look at code snippet from this SO answer :
update t set data=concat(data, 'a');
Something similar should work:
update t set data=concat('http://www.x.com?redirect=', data);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.