我在 GoDaddy 上通过 phyMyAdmin 使用 MySQL。我可以执行这个语句,返回一个整数值,没有任何问题:
SELECT DISTINCT `runNumber` FROM RideSlot WHERE (timeRange = 2) LIMIT 0,1;
但是,当我尝试创建以下存储过程时,出现以下错误:
1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 25 行的 '' 附近使用正确的语法
DROP PROCEDURE IF EXISTS `spGetPreferredRunNumbers`$$
CREATE PROCEDURE `spGetPreferredRunNumbers`(IN prefTimeRange INT(4), INOUT run1 INT(4), INOUT run2 INT(4), INOUT run3 INT(4), INOUT run4 INT(4), INOUT run5 INT(4))
BEGIN
IF (prefTimeRange = 2) THEN BEGIN
SELECT DISTINCT `runNumber` FROM RideSlot WHERE (timeRange = prefTimeRange) LIMIT 0,1 INTO run1;
SELECT DISTINCT `runNumber` FROM RideSlot WHERE (timeRange = prefTimeRange) LIMIT 1,1 INTO run2;
SELECT DISTINCT `runNumber` FROM RideSlot WHERE (timeRange = prefTimeRange) LIMIT 2,1 INTO run3;
SELECT DISTINCT `runNumber` FROM RideSlot WHERE (timeRange = prefTimeRange) LIMIT 3,1 INTO run4;
SET run5 = -1;
END;
ELSE IF (prefTimeRange = 3) THEN BEGIN
SELECT DISTINCT `runNumber` FROM RideSlot WHERE (timeRange = prefTimeRange) LIMIT 0,1 INTO run1;
SELECT DISTINCT `runNumber` FROM RideSlot WHERE (timeRange = prefTimeRange) LIMIT 1,1 INTO run2;
SELECT DISTINCT `runNumber` FROM RideSlot WHERE (timeRange = prefTimeRange) LIMIT 2,1 INTO run3;
SELECT DISTINCT `runNumber` FROM RideSlot WHERE (timeRange = prefTimeRange) LIMIT 3,1 INTO run4;
SET run5 = -1;
END;
ELSE BEGIN
SELECT DISTINCT `runNumber` FROM RideSlot WHERE (timeRange = prefTimeRange) LIMIT 0,1 INTO run1;
SELECT DISTINCT `runNumber` FROM RideSlot WHERE (timeRange = prefTimeRange) LIMIT 1,1 INTO run2;
SELECT DISTINCT `runNumber` FROM RideSlot WHERE (timeRange = prefTimeRange) LIMIT 2,1 INTO run3;
SELECT DISTINCT `runNumber` FROM RideSlot WHERE (timeRange = prefTimeRange) LIMIT 3,1 INTO run4;
SELECT DISTINCT `runNumber` FROM RideSlot WHERE (timeRange = prefTimeRange) LIMIT 4,1 INTO run5;
END;
END IF;
END$$
DELIMITER;
是的,我已经单独测试了具有不同限制的其他选择语句,它们也可以正常工作,除非在选择 LIMIT 4,1 时使用 2 或 3 作为 prefTimeRange。prefTimeRange 的 2 和 3 仅返回四个结果,因此如果 prefTimeRange 为 2 或 3,我将 -1 分配给 run5。
无论我是否这样做,我都会得到同样的错误:prefTimeRange = 3
或者这个: prefTimeRange = "3"
是的,我记得告诉 phpMyAdmin 正确的分隔符是 $$。
我错过了什么????