我有一个数据库表,其中包含一个名为"shortLink“的列。此列包含表中每一行地址的简短链接。我将tinyurl.com服务用于短链接。短链接看起来如下:https://tinyurl .com/randomletters
。
最近,我发现我需要将短链接更改为预览短链接版本:https://preview.tinyurl .com/randomletters
。
这两种链接格式之间唯一的区别是,https://
和tinyurl
之间有一个前缀tinyurl
。
由于sql表中有数百行,所以无法手动修复。是否有任何方法将每个短链接(通过在地址中添加前缀preview.
)转换为具有sql代码的预览格式?
谢谢。
PS -请注意,在上面的链接格式中,tinyurl
和.com
之间存在差距。这个空白是故意增加的,因为论坛不让我发表这个问题。
发布于 2018-05-10 12:45:30
--这将为您更新没有预览的字段。在里面。
UPDATE YourTable
SET shortlinks= REPLACE( shortlinks, 'https://tinyurl .com', 'https://preview.tinyurl .com')
WHERE shortlinks NOT LIKE 'https://preview.tinyurl%'
发布于 2018-05-10 12:45:16
您可以只使用update
update t
set shortlink = concat('http://preview.', substring(shortlink, 8))
where shorlink like 'http://tinyurl%';
发布于 2018-05-10 13:15:26
兄弟,试试这个。首先,删除URL中任何位置的所有空格,然后将“tinyurl”替换为“预览”
UPDATE [Table_Name]
SET shortLink= REPLACE(REPLACE( shortLink, ' ', ''),'tinyurl', 'preview')
https://stackoverflow.com/questions/50273244
复制相似问题