本篇内容介绍了“数据库实用脚本方法教程”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
1、SQLServer脚本
–-计算地球上两个坐标点(经度,纬度)之间距离sql函数 CREATE FUNCTION [dbo].[fnGetDistance](@LatBegin REAL, @LngBegin REAL, @LatEnd REAL, @LngEnd REAL) RETURNS FLOAT AS BEGIN –-距离(千米) DECLARE @Distance REAL DECLARE @EARTH_RADIUS REAL SET @EARTH_RADIUS = 6378.137 DECLARE @RadLatBegin REAL,@RadLatEnd REAL,@RadLatDiff REAL,@RadLngDiff REAL SET @RadLatBegin = @LatBegin *PI()/180.0 SET @RadLatEnd = @LatEnd *PI()/180.0 SET @RadLatDiff = @RadLatBegin - @RadLatEnd SET @RadLngDiff = @LngBegin *PI()/180.0 - @LngEnd *PI()/180.0 SET @Distance = 2 *ASIN(SQRT(POWER(SIN(@RadLatDiff/2), 2) +COS(@RadLatBegin)*COS(@RadLatEnd)*POWER(SIN(@RadLngDiff/2), 2))) SET @Distance = @Distance * @EARTH_RADIUS RETURN @Distance END --使用方法如下: SELECT dbo.fnGetDistance(25,30,12.56,15.5) ;
2、MySQl脚本
–-计算地球上两个坐标点(经度,纬度)之间距离sql函数 CREATE FUNCTION [dbo].[fnGetDistance](@LatBegin REAL, @LngBegin REAL, @LatEnd REAL, @LngEnd REAL) RETURNS FLOAT AS BEGIN –-距离(千米) DECLARE @Distance REAL DECLARE @EARTH_RADIUS REAL SET @EARTH_RADIUS = 6378.137 DECLARE @RadLatBegin REAL,@RadLatEnd REAL,@RadLatDiff REAL,@RadLngDiff REAL SET @RadLatBegin = @LatBegin *PI()/180.0 SET @RadLatEnd = @LatEnd *PI()/180.0 SET @RadLatDiff = @RadLatBegin - @RadLatEnd SET @RadLngDiff = @LngBegin *PI()/180.0 - @LngEnd *PI()/180.0 SET @Distance = 2 *ASIN(SQRT(POWER(SIN(@RadLatDiff/2), 2) +COS(@RadLatBegin)*COS(@RadLatEnd)*POWER(SIN(@RadLngDiff/2), 2))) SET @Distance = @Distance * @EARTH_RADIUS RETURN @Distance END --使用方法如下: SELECT dbo.fnGetDistance(25,30,12.56,15.5) ;
3、Orcale脚本
CREATE OR REPLACE FUNCTION GetDistance (lat1 number, lng1 number,lat2 number,lng2 number) RETURN NUMBER is earth_padius number := 6378.137; radLat1 number := Radian(lat1); radLat2 number := Radian(lat2); a number := radLat1 - radLat2; b number := Radian(lng1) - Radian(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; --使用方法 select GetDistance(25,30,12.56,15.5) from dual
“数据库实用脚本方法教程”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。