0

我想用 SQL 数据库中的另一个替换一个 html 字符串。我知道主要语法,但字符串有 html 标签。

这是一个例子:

update wp_posts 
set post_content = replace(post_content, '<img alt="100%" id="home-img" src="/wp-content/themes/wp-theme/images/100pc.png">'
, '<a href="fblink" target="_blank" class="facebook"></a><img alt="100%" id="home-img" src="/wp-content/themes/wp-theme/images/100pc.png">'
);

我想我应该知道正确的语法,但我认为问题出在“、>、= 字符上。

谢谢您的帮助。

4

1 回答 1

0

这是一个SQL Fiddle,它演示了您使用的是正确的语法。你也可以使用

update wp_posts 
set post_content = '<a href="fblink" target="_blank" class="facebook"></a><img alt="100%" id="home-img" src="/wp-content/themes/wp-theme/images/100pc.png">'
WHERE post_content = '<img alt="100%" id="home-img" src="/wp-content/themes/wp-theme/images/100pc.png">';
于 2013-11-01T13:16:28.477 回答