美文网首页
Mysql去掉html标签函数

Mysql去掉html标签函数

作者: yichen_china | 来源:发表于2021-11-24 11:21 被阅读0次

函数

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),content FROM `t_knowledgenew`;
image

相关文章

网友评论

      本文标题:Mysql去掉html标签函数

      本文链接:https://www.haomeiwen.com/subject/ezjntrtx.html