USE `test`;
DROP function IF EXISTS `getSubNum`;
DELIMITER $$
USE `test`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `getSubNum`(str varchar(250),substr varchar(250)) RETURNS int(11)
BEGIN
declare num int default 0;
declare indexStr int;
set indexStr=INSTR(str, substr);
while indexStr !=0 do
set num = num + 1;
set str=SUBSTRING(str,indexStr+LENGTH(substr)-1);
set indexStr=INSTR(str, substr);
end while;
RETURN num;
END$$
DELIMITER ;
mysql自定义函数实现统计一个字符串在另一个长字符串中出现的次数
最新推荐文章于 2022-12-03 20:39:36 发布