我試圖在MySQL 5.5.38中編寫我第一個存儲的函數,但是我無法通過令人討厭的語法錯誤。我已經檢查過MySQL文檔,但是我仍然看不到問題所在,並且錯誤消息僅顯示You have an error in your SQL syntax; blah blah blah ... at line 1
。創建存儲函數時出現語法錯誤
下面的代碼:
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)
)
);
RETURN dist;
END$$
DELIMITER ;
編輯:確切的錯誤信息是:
SQL Error [1064] [42000]: 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 'DELIMITER $$
CREATE FUNCTION distm (lat1 DOUBLE, lng1 DOUBLE, lat2 DOUBLE, lng2' at line 1
你嘗試IF EXISTS distm刪除'DROP功能之後;'? – 2014-10-06 17:05:32
它絕對不會說'等等等等等等..如果你想得到進一步的幫助,發佈確切的錯誤。 – Rahul 2014-10-06 17:06:08
@Rahul你說得對,我已經添加了確切的錯誤信息。 – 2014-10-06 17:25:37