gpt4 book ai didi

mysql - 仅当不包含给定部分时才替换 URL 的一部分

转载 作者:行者123 更新时间:2023-11-29 02:21:15 32 4
gpt4 key购买 nike

我需要将所有包含 31.media.tumblr.com 的 URL 替换为 41.media.tumblr.com。但是,如果 URL 31.media.tumblr.com 中有 .gif,则不得更改。

这是我的代码;但它会更改所有内容,甚至是其中包含 .gif 的 URL...当我运行它时:

UPDATE wp_posts 
SET post_content
= REPLACE(post_content
,'31.media.tumblr.com/'
,'41.media.tumblr.com/')
WHERE post_content LIKE '%31.media.tumblr.com/%'
AND post_content NOT LIKE '%.gif';

附注这是 31.url 的示例,末尾带有 gif

https://31.media.tumblr.com/79db8c1df4f893bc20d53063e03834f6/tumblr_n1e93kMh3z1rjbi2lo1_500.gif

最佳答案

您的查询看起来不错,我认为问题出在 post_content 中的尾随空格。尝试:

UPDATE wp_posts 
SET post_content
= REPLACE(post_content
,'31.media.tumblr.com/'
,'41.media.tumblr.com/')
WHERE post_content LIKE '%31.media.tumblr.com/%'
AND rtrim(post_content) NOT LIKE '%.gif';

看看是否有帮助。测试用例:

create table wp_posts (post_content varchar(255));
insert into wp_posts
values ('https://31.media.tumblr.com/79db8c1df4f893bc20d53063e03834f6/tumblr_n1e93kMh3z1rjbi2lo1_500.gif')
insert into wp_posts
values ('https://31.media.tumblr.com/79db8c1df4f893bc20d53063e03834f6/tumblr_n1e93kMh3z1rjbi2lo1_500.gif ');

select * from wp_posts
where post_content LIKE '%31.media.tumblr.com/%'
AND post_content NOT LIKE '%.gif';
[...]
1 row in set (0.00 sec)

select * from wp_posts
where post_content LIKE '%31.media.tumblr.com/%'
AND rtrim(post_content) NOT LIKE '%.gif';
[...]
Empty set (0.00 sec)

关于mysql - 仅当不包含给定部分时才替换 URL 的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31545252/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com