“错误#1313 RETURN仅在功能中允许”在phpMyAdmin中创建存储过程时

时间:2011-08-26 01:22:09

标签: mysql stored-procedures phpmyadmin

我正在尝试在phpMyAdmin中创建以下存储过程。但是,我一直收到这个错误:#1313 - 只允许在功能

中使用RETURN
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窗格中,我记得将分隔符更改为//。

有什么建议吗?

1 个答案:

答案 0 :(得分:4)

错误消息可以准确地告诉您问题所在 - 您无法在RETURN中使用PROCEDURE。改为创建一个FUNCTIONCREATE FUNCTION),它可以返回一个值。

CREATE FUNCTION <FunctionName> RETURNS <DataType>