Friday 15 May 2015

mysql - Syntax error when creating stored function -



mysql - Syntax error when creating stored function -

i'm trying write first stored function in mysql 5.5.38, cannot past annoying syntax error. checked mysql docs, still can't see problem , error message says you have error in sql syntax; blah blah blah ... @ line 1.

here's code:

delimiter $$ create function distm (lat1 double, lng1 double, lat2 double, lng2 double) returns double no sql deterministic begin declare radius double; set radius = 6371008.771415059; declare x1, y1, x2, y2, dlat, dlng double; set x1 = radians(lng1); set y1 = radians(lat1); set x2 = radians(lng2); set y2 = radians(lat2); set dlng = x2 - x1; set dlat = y2 - y1; declare dist double; set dist = 2 * radius * asin( sqrt( pow(sin(dlat / 2), 2) + cos(y1) * cos(y2) * pow(sin(dlng / 2), 2) ) ); homecoming dist; end$$ delimiter ;

edit: exact error message following:

sql error [1064] [42000]: have error in sql syntax; check manual corresponds mysql server version right syntax utilize near 'delimiter $$ create function distm (lat1 double, lng1 double, lat2 double, lng2' @ line 1

try removing drop statement before delimiter $$ , run again.

also, alter line returns double no sql deterministic below. notice, it's not no sql deterministic rather not deterministic

returns double not deterministic

mysql syntax-error stored-functions

No comments:

Post a Comment