【问题标题】:Replace dynamic text SQL替换动态文本 SQL
【发布时间】:2012-10-18 02:42:57
【问题描述】:

谁能帮我解决一个我无法解决的小问题。我正在尝试更新 php_text 中的 bbcode 标记

Exemple [i] => [i:rlj7bc53]
Exemple [u] => [u:rlj7bc53]
Exemple [b] => [/b:rlj7bc53]

还有

[quote="Christo"] => [quote="Christo":rlj7bc53]

暂时我已经使用了这个请求。

update phpbb_posts
   set post_text = replace(post_text, '[/quote]' , '[/quote:rlj7bc53]')

【问题讨论】:

  • 您使用的是哪个 DBMS?例如,Oracle 的 regexp_replace 对此非常有用。

标签: sql design-patterns dynamic replace


【解决方案1】:

在运行更新之前对其进行测试:

SELECT post_text as [OldTag]
      ,'[' + SUBSTRING(post_text, 2, (LEN(post_text) - 2)) + ':rlj7bc53]' AS [NewTag]
FROM phpbb_posts

实际更新:

UPDATE phpbb_posts
SET post_text = '[' + SUBSTRING(post_text, 2, (LEN(post_text) - 2)) + ':rlj7bc53]'

请注意,他将通过添加 :rlj7bc53 来更新该列上 [ 和 ] 之间的所有文本。 如果您只想替换列上的特定标签,您可以执行以下操作:

  UPDATE phpbb_posts
  SET post_text = '[' + SUBSTRING(post_text, 2, (LEN(post_text) - 2)) + ':rlj7bc53]'
  WHERE post_text = [i]
     OR post_text = [u]
     OR post_text = [/quote]

【讨论】:

  • 谢谢。你的回答真的很有帮助
  • 我知道已经快3年了,但如果对您有帮助,请将答案标记为正确:)
猜你喜欢
  • 2013-05-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-10
  • 2013-12-13
  • 2022-12-05
  • 2018-12-22
  • 2012-09-04
相关资源
最近更新 更多