I've got a weird one: I've got MySQL v5.7.24 on my local machine, and my server. The following code executes fine locally:
DROP FUNCTION IF EXISTS SharingRatio;
CREATE FUNCTION SharingRatio(users int, sharer int, cabins int, outdoors int) RETURNS DECIMAL(6,2)
DETERMINISTIC
READS SQL DATA
BEGIN
DECLARE ratio DECIMAL(6,2);
IF cabins IS NULL THEN
SET cabins = 0;
END IF;
IF sharer IS NULL THEN
SET sharer = 1;
END IF;
IF users IS NULL THEN
SET users = 1;
END IF;
SELECT IF(sharer = 1, telco1, IF(sharer = 2, telco2, IF(sharer = 3, telco3, IF(sharer =4, telco4, IF(sharer = 5, telco5, null)))))
FROM rates r WHERE (r.type='Utility' and r.cabin = cabins and if(outdoors IS NULL, true, r.outdoor = outdoors) and r.users = users) LIMIT 1 INTO ratio;
IF ratio IS NULL THEN
SET ratio = ROUND(100 / users, 2) ;
END IF;
RETURN (ratio);
END;
DROP FUNCTION IF EXISTS SharingValue;
CREATE FUNCTION SharingValue(value decimal(10,2), users int, sharer int, cabins int, outdoors int) RETURNS DECIMAL(10,2)
DETERMINISTIC
READS SQL DATA
BEGIN
DECLARE ratio DECIMAL(6,2);
IF value IS NULL THEN
RETURN NULL;
END IF;
IF cabins IS NULL THEN
SET cabins = 0;
END IF;
IF sharer IS NULL THEN
SET sharer = 1;
END IF;
IF users IS NULL THEN
SET users = 1;
END IF;
SET ratio = SharingRatio(users, sharer, cabins, outdoors);
RETURN CAST(value * (ratio / 100) AS DECIMAL(10,2));
END;
However, when I deploy, via MySQLAdmin, with root access rights, I get the infamous #1064 error saying error in line 5 near ''.
I've looked at a number of other posts, no dangling commas, no ELSE IF to cause problems. Frankly, I'm stuck!