我有一个错误的 MySQL 函数。
CREATE FUNCTION getpolygon(lat DOUBLE, lon DOUBLE, radius SMALLINT, corner TINYINT)
RETURNS geometry
DETERMINISTIC
BEGIN
DECLARE i INT;
DECLARE a, b, c DOUBLE;
DECLARE res TEXT;
IF corner < 3 || radius > 500 THEN
RETURN NULL;
END IF;
SET res = CONCAT(lat + radius / 111.12, ' ', lon, ',');
WHILE i < corner do
SET c = RADIANS(360 / corner * i);
SET a = lat + COS(c) * radius / 111.12;
SET b = lon + SIN(c) * radius / (COS(RADIANS(lat + COS(c) * radius / 111.12 / 111.12)) * 111.12);
SET res = CONCAT(res, a, ' ', b, ',');
SET i = i + 1;
END WHILE;
RETURN GEOMFROMTEXT(CONCAT('POLYGON((', res, lat + radius / 111.12, ' ', lon, '))'));
END;
当我运行此代码时,MySQL 服务器说:“SQL 错误 1064 ..... nerar '' at line 5”
问题是什么?
我感谢你的帮助!