我有一张桌子叫
故事
有一列
body
每个主体都包含以前CMS中封装在标签soltag之间的php/html代码。
例如,有一张唱片是这样的:
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting
[soltag]php, $end = ""; if (isset($_GET["vote"])) { $end .= "?vote=" . $_GET["vote"]; if (isset($_GET["vid"])) { $end .= "&vid=" . $_GET["vid"]; }; }; $output = file_get_contents("http://example.com/something.html" . $end);[/soltag] And the body text continues here.我想从数据库中的每一条记录中删除这些标记之间的所有内容,包括这些标记。
因此,在此之后,应该是:
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting And the body text continues here.我有大约5000张记录,所以手动它将消耗至少2-3天的机器人般的工作。
有任何想法吗?我如何用mysql命令删除它?
提前谢谢。
发布于 2011-11-04 12:56:32
为了类似的目的,我搜索了类似的东西,这是非常有用的。
只有一件事..。对于下一个搜索相同问题的用户。
如果还希望删除结束标记,则应在SUBSTRING的第三个参数中对结束标记的字符串长度进行求和:
更新故事集正文=替换( body,
SUBSTRING(body,INSTR(body,'soltag'),INSTR(body,'/soltag') +CHAR_LENGTH(/soltag) -INSTR(body,'soltag'),'');
希望这对某人有帮助!)
发布于 2011-09-08 05:19:38
使用SUBSTRING()和INSTR()帮助完成此任务。
在更新列之前,请确保您拥有正确的数据。
SELECT REPLACE([body],
SUBSTRING([body],
INSTR([body],'[soltag]'),
INSTR([body],'[/soltag]') -INSTR([body],'[soltag]')
)
,'') AS NewBody
From [stories]如果INSTR()关闭1,则根据需要调整上面的内容。
然后可以更新此表中的所有列。
UPDATE stories
SET [body] = REPLACE([body],
SUBSTRING([body],
INSTR([body],'[soltag]'),
INSTR([body],'[/soltag]') -INSTR([body],'[soltag]')
)
,'')https://stackoverflow.com/questions/7343349
复制相似问题