create or replace function getDistance(lon1 in number, lat1 in number,lon2 in number,lat2 in number) return number as
dd number := 0;
radius number := 6378140.0;
PI number := 3.1415926535897932384626433832795028842;
begin
dd := (2*ATAN2(SQRT(SIN((lat1-lat2)*PI/180/2)
*SIN((lat1-lat2)*PI/180/2)+
COS(lat2*PI/180)*COS(lat1*PI/180)
*SIN((lon1-lon2)*PI/180/2)
*SIN((lon1-lon2)*PI/180/2)),
SQRT(1-SIN((lat1-lat2)*PI/180/2)
*SIN((lat1-lat2)*PI/180/2)
+COS(lat2*PI/180)*COS(lat1*PI/180)
*SIN((lon1-lon2)*PI/180/2)
*SIN((lon1-lon2)*PI/180/2))))*radius;
return dd;
end getDistance;
dd number := 0;
radius number := 6378140.0;
PI number := 3.1415926535897932384626433832795028842;
begin
dd := (2*ATAN2(SQRT(SIN((lat1-lat2)*PI/180/2)
*SIN((lat1-lat2)*PI/180/2)+
COS(lat2*PI/180)*COS(lat1*PI/180)
*SIN((lon1-lon2)*PI/180/2)
*SIN((lon1-lon2)*PI/180/2)),
SQRT(1-SIN((lat1-lat2)*PI/180/2)
*SIN((lat1-lat2)*PI/180/2)
+COS(lat2*PI/180)*COS(lat1*PI/180)
*SIN((lon1-lon2)*PI/180/2)
*SIN((lon1-lon2)*PI/180/2))))*radius;
return dd;
end getDistance;