- 创建替换函数
以下函数取自网上版本,暂时没细研究
SET GLOBAL log_bin_trust_function_creators=1;
DROP FUNCTION IF EXISTS fnStripTags;
DELIMITER |
CREATE FUNCTION fnStripTags( Dirty text(0) )
RETURNS text(0)
DETERMINISTIC
BEGIN
DECLARE iStart, iEnd, iLength int;
WHILE Locate( '<', Dirty ) > 0 And Locate( '>', Dirty, Locate( '<', Dirty )) > 0 DO
BEGIN
SET iStart = Locate( '<', Dirty ), iEnd = Locate( '>', Dirty, Locate('<', Dirty ));
SET iLength = ( iEnd - iStart) + 1;
IF iLength > 0 THEN
BEGIN
SET Dirty = Insert( Dirty, iStart, iLength, '');
END;
END IF;
END;
END WHILE;
RETURN Dirty;
END;
|
DELIMITER ;
- 执行
select fnStripTags(content);
#如果需要保留换行,可先替换br为\r\n
select fnStripTags(replace(content,'<br />','\r\n'))
作者
Abul
发表于
2021-05-21 16:39:44
,并被添加「
mysql
」标签
,最后修改于
2022-07-11 18:03:35
Comments