CREATE FUNCTION DBREAD.GETDISTANCE
("LNG1" DOUBLE,
"LAT1" DOUBLE,
"LNG2" DOUBLE,
"LAT2" DOUBLE
)
RETURNS INTEGER
SPECIFIC DBREAD.SQL141104134103400
LANGUAGE SQL
NOT DETERMINISTIC
READS SQL DATA
STATIC DISPATCH
CALLED ON NULL INPUT
EXTERNAL ACTION
INHERIT SPECIAL REGISTERS
BEGIN ATOMIC
DECLARE earth_padius double;
DECLARE radLat1 double;
DECLARE radLat2 double;
DECLARE a double;
DECLARE b double;
DECLARE s double;
set earth_padius= 6378137.0;
set radLat1 = RADIANS(lat1);
set radLat2 = RADIANS(lat2);
set a = radLat1 - radLat2;
set b = RADIANS(lng1) - RADIANS(lng2);
set s = 0;
set s = 2 * Asin(Sqrt(power(sin(a / 2), 2) + cos(radLat1) * cos(radLat2) *
power(sin(b / 2), 2)));
set s = s * earth_padius;
set s = CEILING(Round(s,0));
return s;
end;
("LNG1" DOUBLE,
"LAT1" DOUBLE,
"LNG2" DOUBLE,
"LAT2" DOUBLE
)
RETURNS INTEGER
SPECIFIC DBREAD.SQL141104134103400
LANGUAGE SQL
NOT DETERMINISTIC
READS SQL DATA
STATIC DISPATCH
CALLED ON NULL INPUT
EXTERNAL ACTION
INHERIT SPECIAL REGISTERS
BEGIN ATOMIC
DECLARE earth_padius double;
DECLARE radLat1 double;
DECLARE radLat2 double;
DECLARE a double;
DECLARE b double;
DECLARE s double;
set earth_padius= 6378137.0;
set radLat1 = RADIANS(lat1);
set radLat2 = RADIANS(lat2);
set a = radLat1 - radLat2;
set b = RADIANS(lng1) - RADIANS(lng2);
set s = 0;
set s = 2 * Asin(Sqrt(power(sin(a / 2), 2) + cos(radLat1) * cos(radLat2) *
power(sin(b / 2), 2)));
set s = s * earth_padius;
set s = CEILING(Round(s,0));
return s;
end;