【问题标题】:Remove and Replace all html content in SQL删除和替换 SQL 中的所有 html 内容
【发布时间】:2015-05-03 15:52:38
【问题描述】:

我希望 SQL Server 中的查询通过删除其所有 html 内容来更新数据。

请参阅下面的示例数据。

这是一个示例文本。

<html><head></head><body><p>This is a sample text.</p></body></html>

我只需要保留纯文本并删除所有这些 html 内容,包括标签。我想,参考可能是从&lt;html**/html &gt;

有什么建议吗?

【问题讨论】:

  • 使用替换功能,您可以通过此功能将替换为空格

标签: sql sql-server replace substring


【解决方案1】:

Charindex + While Loop。试试这个。

DECLARE @html  VARCHAR(5000)='This is a sample text < html >< head ></head >< body >< p >This is a sample text.< p >< /body >< /html >',
        @start INT,
        @end   INT

WHILE Charindex('<', @html) > 0
  BEGIN
      SET @start= Charindex('<', @html)
      SET @end = Charindex('>', @html)

      SELECT @html = Stuff(@html, @start, ( @end - @start ) + 1, '')
  END

SELECT @html --This is a sample text This is a sample text.

【讨论】:

  • 嗨,谢谢,这适用于所有具有 html 的行吗?每条记录都有纯文本版本和 html 版本。
  • 这将删除 之间的所有单词
猜你喜欢
  • 2010-12-12
  • 1970-01-01
  • 2019-01-06
  • 1970-01-01
  • 2014-02-05
  • 1970-01-01
  • 2011-06-05
  • 2017-04-16
  • 2014-01-11
相关资源
最近更新 更多