Calculate distance from lat lng

CREATE function distance_between (
    P_FROM_LAT IN NUMBER, P_TO_LAT IN NUMBER,
    P_FROM_LON IN NUMBER, P_TO_LON IN NUMBER
) RETURN NUMBER AS
        RETVAL NUMBER;
    BEGIN
       RETURN ROUND (SQRT (
       (69.1 * (P_FROM_LAT - P_TO_LAT)) * (69.1 * (P_FROM_LAT - P_TO_LAT)) +
       (53.0 * (P_FROM_LON - P_TO_LON)) * (53.0 * (P_FROM_LON - P_TO_LON))), 1);
      EXCEPTION
      WHEN OTHERS THEN
        RETURN NULL;
    END;
/

Leave a Reply