1.第一步
-- 1.开启自定义函数
SET GLOBAL log_bin_trust_function_creators=1;
-- 2.如果存在该函数则删除
DROP FUNCTION IF EXISTS fnStripTags;
-- 3.执行自定义函数
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 ;
2.第二步执行sql
SELECT content,del_html( content ) FROM cms_content;
注意:如果执行sql 报错为以下信息
Illegal mix of collations (utf8mb4_general_ci,COERCIBLE) and (utf8mb4_0900_ai_ci,COERCIBLE) for operation 'like'
可改为一下sql例如:
SELECT
*
FROM
cms_content
WHERE
CONVERT(del_html( content ) USING utf8) COLLATE utf8_unicode_ci LIKE '%4%'
总结:如果使用 函数结果 进行匹配会报 编码和排序规则 不一致
where CONVERT(del_html(字段) USING utf8) COLLATE utf8_unicode_ci LIKE '%4%' 用来解决问题,有更好的解决方式请留言
来源地址:https://blog.csdn.net/qq_37782946/article/details/130849637