使用 SQL UPDATE 查询替换所有行的列值中的子字符串
这是一个示例表:
name | picture
John S. | http://servera.host.com/johns.png
Linda B. | http://servera.host.com/lindab.png
...
假设还有数百条记录。
假设我们将服务器从“servera”移动到“serverb”。
是否可以使用一个查询进入此表,为每条记录重命名“图片”列中的内容,以读取正确的服务器名称?
Here's a sample table:
name | picture
John S. | http://servera.host.com/johns.png
Linda B. | http://servera.host.com/lindab.png
...
Let's say there are several hundred more records.
Let's also say we moved servers from "servera" to "serverb".
Would it be possible to go into this table with one query to rename the content in the column "picture" for every record to read the correct server name?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
T-SQL:
Oracle:
MySQL:
T-SQL:
Oracle:
MySQL:
我包含了更多的字符串,因为我担心“修复”名为“somethingserverasomething.jpg”的图像。我可能还会考虑拥有一个 base_url 表并仅在用户中存储图像文件名,但这不是您问的问题;-)
I'm including more of the string because I'd worry about 'fixing' an image named 'somethingserverasomething.jpg'. I might also think about having a base_url table and just storing image file names in users, but that's not the question you asked ;-)