DELIMITER ;;
CREATE FUNCTION `substrCount`(s varchar(65530), ss VARCHAR(255)) RETURNS mediumint(8) unsigned
BEGIN
DECLARE count MEDIUMINT(4);
DECLARE offset MEDIUMINT(4);
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET s = NULL;
SET count = 0;
SET offset = 1;
REPEAT
IF NOT ISNULL(s) AND offset > 0 THEN
SET offset = LOCATE(ss, s, offset);
IF offset > 0 THEN
SET count = count + 1;
SET offset = offset + 1;
END IF;
END IF;
UNTIL ISNULL(s) OR offset = 0 END REPEAT;
RETURN count;
END ;;
DELIMITER ;
它在10.2 MariaDB中运行正常,但在10.6.8中出现语法错误
SQL错误(1064):您的SQL语法中有错误;检查与您的MariaDB服务器版本对应的手册,以了解使用near 'offset MEDIUMINT(4)的正确语法;在第4行为SQLSTATE '02000' SET s = N...'声明继续处理程序 */
1条答案
按热度按时间idv4meu81#
Offset
在10.6中成为保留关键字,现在需要用引号引起来(或更改变量名)。