开发者

add the same thing to a table column by sql command

there is a table named test. in it. there are some columns as this:

001.jpg
  ...
999.jpg

now i want to use a sql command to开发者_开发知识库 add a url before them. as this http://www.example.com/xxx/001.jpg.....is there a way to get this? thank you.


There is two way to accomplish this task. It depends up to you that what you want?

If you want to add a url in the database permanently then you have to use update query with no any where condition, Although if you want to only show your field with this added url you have to use select query.

Please find below the examples for both:

Suppose that your table column name is imageName then UPDATE query will be

UPDATE test SET imageName = CONCAT("http://www.example.com/xxx/", imageName);

And the SELECT query will be

SELECT CONCAT("http://www.example.com/xxx/", imageName) FROM test;


Supposing that your field is called url, a simple UPDATE query will do:

UPDATE test SET url = CONCAT("http://", url);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜