Home > Enterprise >  Not able to creat funtion in mariaDB 10.6.8, but was working in 10.2
Not able to creat funtion in mariaDB 10.6.8, but was working in 10.2

Time:05-27

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 ;

It was working fine in 10.2 MariaDB but getting syntax error in 10.6.8

SQL Error (1064): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'offset MEDIUMINT(4); DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET s = N...' at line 4 */

CodePudding user response:

Offset became a reserved keyword in 10.6 and now needs to be quoted (or change your variable name).

  • Related