gpt4 book ai didi

mysql - 第一行创建mysql存储过程出错

转载 作者:行者123 更新时间:2023-11-29 08:16:05 25 4
gpt4 key购买 nike

我正在尝试在 MySQL Community Server 5.5.32 版本中创建存储过程,但我的过程在第一行返回错误,但我找不到它。谁能帮我吗?

CREATE PROCEDURE nearestPanel (IN mylat DOUBLE, IN mylon DOUBLE) 
BEGIN
DECLARE dist DOUBLE DEFAULT 62.14;
DECLARE lon1 DOUBLE DEFAULT 0;
DECLARE lon2 DOUBLE DEFAULT 0;
DECLARE lat1 DOUBLE DEFAULT 0;
DECLARE lat2 DOUBLE DEFAULT 0;
DECLARE today TIMESTAMP DEFAULT CURRENT_DATE;

SET lon1 = mylon-dist/abs(cos(radians(mylat))*69);
SET lon2 = mylon+dist/abs(cos(radians(mylat))*69);
SET lat1 = mylat-(dist/69);
SET lat2 = mylat+(dist/69);

SELECT
panels.name,
panels.description,
cells.*,
3956 * 2 * ASIN(SQRT(POWER(SIN((mylat - panels.latitude) * pi()/180 / 2), 2) +COS(mylat * pi()/180) * COS(panels.latitude * pi()/180) * POWER(SIN((mylon -panels.longitude) * pi()/180 / 2), 2))) AS distance
FROM
cells
INNER JOIN
panels
ON
cells.panel_id = panels.id
WHERE
panels.longitude BETWEEN lon1 AND lon2
AND
panels.latitude BETWEEN lat1 AND lat2
AND
today BETWEEN panels.date_start AND panels.date_end
HAVING
distance < dist
ORDER BY
distance LIMIT 1;
END

最佳答案

由于该过程包含分号,因此您需要暂时将分隔符从 ; 更改为 //;

DELIMITER //
CREATE PROCEDURE nearestPanel (IN mylat DOUBLE, IN mylon DOUBLE)
BEGIN
DECLARE dist DOUBLE DEFAULT 62.14;
DECLARE lon1 DOUBLE DEFAULT 0;
...
HAVING
distance < dist
ORDER BY
distance LIMIT 1;
END//
DELIMITER ;

An SQLfiddle to test with, note the delimiter set to // in the dropdown below the code .

关于mysql - 第一行创建mysql存储过程出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20585181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com