0

我试图实现存储过程

DELIMITER $$
    CREATE PROCEDURE FindRadius(IN stop_lat float,IN stop_lng float,IN lat float,IN lng float,OUT radius float)
    BEGIN 
    declare R INT DEFAULT 6371;
    declare dLat float;
    declare dLon float;
    declare a float;
    declare c float;
    dLat = RADIANS(stop_lat-lat);  
    dLon = RADIANS(stop_lng-lng); 
     a =  SIN(dLat/2) * SIN(dLat/2) +COS(RADIANS(stop_lat)) * COS(RADIANS(lat)) * SIN(dLon/2) *SIN(dLon/2); 
     c = 2 * ATAN2(SQRT(a),SQRT(1-a)); 
    SET radius = R * c *1000; 
    END$$
    DELIMITER ; 

它抛出错误,说您的 SQL 语法有错误;

RADIANS(stop_lat-lat); dLon = RADIANS(stop_lng-lng); a = SIN(dLat/2) * SI' at line 8

我不知道为什么会出现这个错误,谁能帮忙

4

1 回答 1

1

你不应该这样做:

dLat = ....

它应该是:

SET dLat = RADIANS(stop_lat-lat);  
SET dLon = RADIANS(stop_lng-lng); 
SET a =  SIN(dLat/2) * SIN(dLat/2) +COS(RADIANS(stop_lat)) * COS(RADIANS(lat)) * SIN(dLon/2) *SIN(dLon/2); 
SET c = 2 * ATAN2(SQRT(a),SQRT(1-a)); 
于 2013-06-19T06:27:11.310 回答