ORACLE 根据经纬度 距离排序
1.获得弧度的函数。========================
CREATE OR REPLACE FUNCTION RAD(d number) RETURN NUMBER
?is
?PI number :=3.141592625;
?
?begin?
?return? d* PI/180.0;
?end ;
?
?select RAD(360) from dual;
2.根据经纬度计算距离。=====================
CREATE OR REPLACE FUNCTION GetDistance(lat1 number,? lng1 number, lat2 number, lng2 number) RETURN NUMBER is
?? earth_padius number := 6378.137;
?? radLat1????? number := rad(lat1);
?? radLat2????? number := rad(lat2);
?? a??????????? number := radLat1 - radLat2;
?? b??????????? number := rad(lng1) - rad(lng2);
?? s??????????? number := 0;
?begin
?? s := 2 *? Asin(Sqrt(power(sin(a / 2), 2) + cos(radLat1) * cos(radLat2) * power(sin(b / 2), 2)));
?? s := s * earth_padius;
?? s := Round(s * 10000) / 10000;
?? return s;
?
?end;
3.===============================================================
select a.*, GetDistance(‘121.506656‘,‘31.245087‘,a.ZUOBIAO_Y,a.ZUOBIAO_X) JULI from JL_KU a where 1=1? ORDER BY JULI
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。