我在函数结束时收到错误,唯一的提示是它接近 ''

I am getting an error near the end of my function and the only hint is that it is near ''

我已经尝试阅读其他几个与此类似的答案,但据我所知,其中 none 都是以相同的方式修复的。我尝试删除所有新 lines/tabs 以尝试删除不可见字符,甚至只是将其放在一行中。

我不是最擅长 SQL 一旦你过了某个点,所以这个问题只是我没有意识到什么,但任何帮助将不胜感激。

准确的错误是#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 '' at line 66

第 66 行 RETURN points; 就在 END;;

的正上方
DELIMITER ;;
CREATE FUNCTION getPointValue(run_id INT)
RETURNS INT
BEGIN
    DECLARE points INT DEFAULT 0;
    DECLARE total_completions INT DEFAULT 1;
    DECLARE place INT;
    DECLARE time FLOAT(12,4);
    DECLARE style INT;
    DECLARE run_type INT;

    DECLARE percentile FLOAT(12,4);
    DECLARE total_points INT DEFAULT 3000;
    DECLARE percentile_potential INT;

    DECLARE temp FLOAT;

    DECLARE bracket_min INT DEFAULT 0;
    DECLARE bracket_max INT DEFAULT 0;

    SELECT time INTO time FROM surf_run WHERE run_id = run_id;
    SELECT style INTO style FROM surf_run WHERE run_id = run_id;
    SELECT run_type INTO run_type FROM surf_run WHERE run_id = run_id;

    SELECT COUNT(*) INTO place FROM surf_run WHERE time <= time AND style = style AND run_type = run_type AND best_run = TRUE;
    SELECT COUNT(*) INTO total_completions FROM surf_run WHERE style = style AND run_type = run_type AND best = TRUE;

    IF place = 1 THEN
        SET points = 10000;
    ELSE IF place = 2 THEN
        SET points = 7500;
    ELSE IF place = 3 THEN
        SET points = 5000;
    ELSE IF place = 4 THEN
        SET points = 3500;
    ELSE IF place = 5 THEN
        SET points = 2500;
    ELSE

        SET percentile = (place / total_completions);

        IF percentile <= 0.05 THEN
            SET percentile_potential = 3000;
            SET points = 2000;
            SET bracket_min = 0;
            SET bracket_max = total_completions * 0.05;
        ELSE IF percentile <= 0.10 THEN
            SET bracket_max = total_completions * 0.05 + 1;
            SET bracket_max = total_completions * 0.1;
            SET percentile_potential = 2000;
            SET points = 1250;
        ELSE IF percentile <= 0.15 THEN
            SET bracket_max = total_completions * 0.1 + 1;
            SET bracket_max = total_completions * 0.15;
            SET percentile_potential = 1250;
            SET points = 750;
        ELSE IF percentile <= 0.25 THEN
            SET bracket_max = total_completions * 0.15 + 1;
            SET bracket_max = total_completions * 0.25;
            SET percentile_potential = 750;
            SET points = 10;
        END IF;

        SET points = points + GREATEST(0, ROUND(percentile_potential - percentile_potential * LOG(place, bracket_max)));
    END IF;
    RETURN points;
END;;
DELIMITER ;

常见的“美女”语法错误。

您使用 ELSE IF - 在这种情况下 IF 不是替代分支,而是单独的 IF 语句。因此,您获得多个 IF 没有 END IF 的语句,这会产生错误。

调查 MySQL 8.0 Reference Manual / ... / IF Statement - ELSEIF contain/allow space char.

https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=a4450a40ab690e82ffa18bb3978e68c0