I tried to create own function in MySQL, but the code below doesn't work. There is any syntax error, but after 30mins I'm unable to find what is wrong. Any ideas?
DROP FUNCTION IF EXISTS `gps_distance`;;
CREATE FUNCTION `gps_distance`(lat1 FLOAT,lng1 FLOAT,lat2 FLOAT,lng2 FLOAT) RETURNS float
READS SQL DATA
DETERMINISTIC
BEGIN
SET lat1 = lat1 * pi() / 180;
SET lng1 = lng1 * pi() / 180;
SET lat2 = lat2 * pi() / 180;
SET lng2 = lng2 * pi() / 180;
RETURN acos
( cos(lat1)*cos(lng1)*cos(lat2)*cos(lng2)
+ cos(lat1)*sin(lng1)*cos(lat2)*sin(lng2)
+ sin(lat1)*sin(lat2)
) * 6372.795;
END;;
The error is reported on line 6, after BEGIN
clause.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 6
Should it depends on MySQL version (I have 5.6.21)? On PMA version (4.3.0)? I tried to run this query from PHP script, the same problem.
Thanks for answers.