使用带通配符的 UPDATE 和 REPLACE [英] Using UPDATE and REPLACE With Wildcards
问题描述
UPDATE database_posts
SET post_content = REPLACE (post_content,'%submitted by%%%%%', '');
是否可以在 SQL 中使用通配符执行 UPDATE
和 REPLACE
?我正在尝试从 post_content 列中删除作者,之后/包括 %submitted by%%%%%
之后的所有内容.
Is it possible in SQL to perform an UPDATE
and REPLACE
using wildcards? I'm trying to remove the author from the post_content column, everything after/including %submitted by%%%%%
.
submitted by
值总是不同的.我试过使用上面的查询,但没有成功.
The submitted by
value is always different. I've tried using the query above with no luck.
谢谢!!
推荐答案
如果你想把所有的东西都保持在 submitted by
之后,你可以使用 substring_index()
:
If you want to keep everything up to submitted by
and nothing after, you can use substring_index()
:
UPDATE database_posts
SET post_content = SUBSTRING_INDEX(post_content, 'submitted by', 1)
WHERE post_content LIKE '%submitted by%';
我不知道submitted"和by"之间的所有空格是什么,但它们在您的问题中.
I have no idea what all the spaces are between "submitted" and "by", but they are in your question.
这篇关于使用带通配符的 UPDATE 和 REPLACE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!