mysql oracle计算两点之间的距离

mysql函数:

SET FOREIGN_KEY_CHECKS=0;

DROP FUNCTION IF EXISTS `getDistance`;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `getDistance`(`lng1` decimal,`lat1` decimal,`lng2` decimal,`lat2` decimal) RETURNS decimal(18,2)
BEGIN
RETURN round(6378.138*2*asin(sqrt(pow(sin( (lat1*pi()/180-lat2*pi()/180)/2),2)+cos(lat1*pi()/180)*cos(lat2*pi()/180)* pow(sin( (lng1*pi()/180-lng2*pi()/180)/2),2)))*1000);
END
;;
DELIMITER ;

oracle函数:

CREATE OR REPLACE
FUNCTION getDistance(lng1 in number,lat1 in number,lng2 in number,lat2 in number)
RETURN number
as
BEGIN
return round(6378.138*2*asin(sqrt(power(sin( (lat1*ACOS(-1)/180-lat2*ACOS(-1)/180)/2),2)+cos(lat1*ACOS(-1)/180)*cos(lat2*ACOS(-1)/180)* power(sin( (lng1*ACOS(-1)/180-lng2*ACOS(-1)/180)/2),2)))*1000);
END;

后台代码mybatis中调用:

select getDistance(目的地经度,目的地纬度,现在位置经度,现在位置纬度) from table_name;

字符串数字转换数字类型

select max(cast(id as UNSIGNED INTEGER)) as id from table

原文地址:https://www.cnblogs.com/1246447850qqcom/p/7365906.html