【问题标题】:how to remove part of string from all values如何从所有值中删除部分字符串
【发布时间】:2017-04-30 06:28:12
【问题描述】:

我在 url 列中存储了许多图像 URL。我想替换所有像这样的网址

/photobook/20766/725714/image_20766_11_2017-04-29 10:17:27 +0000.jpg

成为

/photobook/20766/725714/image.jpg

所以主要是,我希望所有图像都具有“image.jpg”名称。

注意:这部分

/photobook/20766/725714/

逐行更改。那我该怎么做呢?

【问题讨论】:

  • I want all images to have "image.jpg" name,如果有存储png的图片呢?
  • MySQL wildcard replace的可能重复

标签: mysql


【解决方案1】:
UPDATE yourTable
SET col = CONCAT(SUBSTRING_INDEX(col, '/image', 1),  -- everything before /image
                 '/image.',                          -- add /image.
                 SUBSTRING_INDEX(col, '.', -1))      -- add the file extension
WHERE col LIKE '%/image_%'

点击下面的链接查看显示字符串操作逻辑工作正常的演示。

Rextester

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-04
    • 2018-09-10
    • 2015-12-02
    • 1970-01-01
    • 2021-12-07
    • 2017-09-07
    • 1970-01-01
    • 2017-07-10
    相关资源
    最近更新 更多