计算与lat lng的距离--MySQL函数错误(#1064)

时间:2014-04-03 13:38:59

标签: mysql sql mysql-error-1064

我正在创建一个计算哈希尔距离的函数,但是我得到了Mysql语法错误

  

1064 - 您的SQL语法出错;检查与MySQL服务器版本对应的手册,以便在第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$$

1 个答案:

答案 0 :(得分:1)

我在Mysql中尝试过你的代码,同样没有工作; 但是当我添加一条额外的线时, 这又重新定了分隔符 请检查

END$$
DELIMITER ;

抱歉,如果这也出错了..但对我来说工作正常