我正在尝试实现以下存储过程,但它没有被创建:
DELIMITER //
CREATE Function 'geodistkm'
(lat1 FLOAT , lon1 FLOAT, lat2 FLOAT , lon2 FLOAT)
returns FLOAT
BEGIN
DECLARE pi, q1, q2, q3 FLOAT;
DECLARE rads FLOAT DEFAULT 0;
SET pi = PI();
SET lat1 = lat1 * pi / 180;
SET lon1 = lon1 * pi / 180;
SET lat2 = lat2 * pi / 180;
SET lon2 = lon2 * pi / 180;
SET q1 = COS(lon1-lon2);
SET q2 = COS(lat1-lat2);
SET q3 = COS(lat1+lat2);
SET rads = ACOS( 0.5*((1.0+q1)*q2 - (1.0-q1)*q3) );
RETURN 6378.388 * rads;
END ;
//
DELIMITER ;
我似乎无法弄清楚它有什么问题。
答案 0 :(得分:1)
进行了以下更改:
DELIMITER //
CREATE FUNCTION geodistkm
(lat1 FLOAT , lon1 FLOAT, lat2 FLOAT , lon2 FLOAT)
RETURNS FLOAT
BEGIN
DECLARE pi, q1, q2, q3 FLOAT;
DECLARE rads FLOAT DEFAULT 0;
SET pi = PI();
SET lat1 = lat1 * pi / 180;
SET lon1 = lon1 * pi / 180;
SET lat2 = lat2 * pi / 180;
SET lon2 = lon2 * pi / 180;
SET q1 = COS(lon1-lon2);
SET q2 = COS(lat1-lat2);
SET q3 = COS(lat1+lat2);
SET rads = ACOS( 0.5*((1.0+q1)*q2 - (1.0-q1)*q3) );
RETURN 6378.388 * rads;
END //
DELIMITER ;