我正在尝试在phpMyAdmin中创建以下存储过程。但是,我一直收到此错误:#1313-仅在FUNCTION中允许返回

CREATE PROCEDURE IS_POINT_IN_POLYGON()
BEGIN
DECLARE n INT DEFAULT 0;
DECLARE pX DECIMAL(19,16);
DECLARE pY DECIMAL(19,16);
DECLARE ls LINESTRING;
DECLARE poly1 POINT;
DECLARE poly1X DECIMAL(19,16);
DECLARE poly1Y DECIMAL(19,16);
DECLARE poly2 POINT;
DECLARE poly2X DECIMAL(19,16);
DECLARE poly2Y DECIMAL(19,16);
DECLARE i INT DEFAULT 0;
DECLARE result INT(1) DEFAULT 0;
SET pX = X(p);
SET pY = Y(p);
SET ls = ExteriorRing(poly);
SET poly2 = EndPoint(ls);
SET poly2X = X(poly2);
SET poly2Y = Y(poly2);
SET n = NumPoints(ls);
WHILE i<n DO
SET poly1 = PointN(ls, (i+1));
SET poly1X = X(poly1);
SET poly1Y = Y(poly1);
IF ( ( ( ( poly1X <= pX )
&& ( pX < poly2X ) ) || ( ( poly2X <= pX )
&& ( pX < poly1X ) ) )
&& ( pY > ( poly2Y - poly1Y ) * ( pX - poly1X ) / ( poly2X - poly1X ) + poly1Y ) ) THEN
SET result = !result;
END IF;
SET poly2X = poly1X;
SET poly2Y = poly1Y;
SET i = i + 1;
END WHILE;
RETURN result;
END//


我该如何解决这个问题?我记得在SQL窗格中将分隔符更改为//。

有什么建议么?

最佳答案

错误消息告诉您确切的问题是-您不能在RETURN中使用PROCEDURE。创建一个FUNCTION代替(CREATE FUNCTION),它可以返回一个值。

CREATE FUNCTION <FunctionName> RETURNS <DataType>

关于mysql - 在phpMyAdmin中创建存储过程时,“仅在函数中允许错误#1313返回”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7199113/

10-12 00:02