Question

I am creating a function for calculating the haversian distance but in i am getting the Mysql syntax error

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 8

DELIMITER $$
CREATE FUNCTION GEODIST (lat1 DOUBLE, lon1 DOUBLE, lat2 DOUBLE, lon2 DOUBLE)
RETURNS DOUBLE
DETERMINISTIC
    BEGIN
        DECLARE dist DOUBLE;
        SET dist = round(acos(cos(radians(lat1)) * cos(radians(lon1)) * cos(radians(lat2)) * cos(radians(lon2)) +  cos(radians(lat1)) * sin(radians(lon1)) * cos(radians(lat2)) * sin(radians(lon2)) + sin(radians(lat1)) * sin(radians(lat2))) * 6378.8, 1);
    RETURN dist;
END$$
Was it helpful?

Solution

I have tried your code in Mysql,and the same didn't work ; but instead when I added an extra line it worked, which was resetting the delimiter again Kindly check

END$$
DELIMITER ;

And sorry in case if this also goes wrong..But worked fine for me

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top