Error creating mysql function [closed]

0

I'm trying to create the following function:

DELIMITER //
FUNCTION DISTANCIA ( lat1 DOUBLE, long1 DOUBLE,  lat2 DOUBLE,  long2 DOUBLE )   RETURNS DOUBLE
DETERMINISTIC
BEGIN
    DECLARE d2r DOUBLE;
    DECLARE dlong DOUBLE;
    DECLARE dlat DOUBLE;
    DECLARE temp_sin DOUBLE;
    DECLARE temp_cos DOUBLE;
    DECLARE temp_cos2 DOUBLE;
    DECLARE temp_sin2 DOUBLE;
    DECLARE a DOUBLE;
    DECLARE c DOUBLE;

    set d2r = 0.017453292519943295769236;

    set dlong = (long2 - long1) * d2r;
    set dlat = (lat2 - lat1) * d2r;

    set temp_sin = sin(dlat/2.0);
    set temp_cos = cos(lat1 * d2r);
    set temp_cos2 = cos(lat2 * d2r);
    set temp_sin2 = sin(dlong/2.0);

    set a = (temp_sin * temp_sin2) + (temp_cos * temp_cos2) * (temp_sin2);
    set c = 2.0 * atan2(sqrt(a), sqrt(1.0 - a));

    return 6368.1 * c;
END //

And this returns me the following error, what could it be?

  

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use

     

near 'FUNCTION DISTANCE (lat1 DOUBLE, long1 DOUBLE, lat2 DOUBLE,   long2 DOUBLE) 'at line 1

The first line there is:

FUNCTION DISTANCIA ( lat1 DOUBLE, long1 DOUBLE,  lat2 DOUBLE,  long2 DOUBLE )   RETURNS DOUBLE
    
asked by anonymous 14.01.2017 / 02:21

1 answer

1

CREATE was missing before FUNCTION

...
CREATE FUNCTION DISTANCIA ( lat1 DOUBLE, long1 DOUBLE,  lat2 DOUBLE,  long2 DOUBLE )   RETURNS DOUBLE
...
    
14.01.2017 / 02:31