Mysql Create函数不起作用

时间:2015-11-09 08:58:58

标签: mysql sql function

我尝试在我的mysql服务器5.5中创建此函数,我从mysql中获取标准错误:

  

1064 - 您的SQL语法出错;检查与MySQL服务器版本对应的手册,以获得正确的语法

     

在第5行附近

SET @query = CONCAT('delete from applicationpackagefeature where featureid in (
',@features,')');

PREPARE stmt FROM @query; EXECUTE stmt; DEALLOCATE PREPARE stmt;

是否有人知道这个问题?

1 个答案:

答案 0 :(得分:1)

<强> Add delimiter

  

每个存储的程序都包含一个由SQL语句组成的主体。   本声明可能是由多个声明组成的复合声明   由分号(;)字符分隔的语句。

     

如果使用mysql客户端程序来定义存储的程序   包含分号字符,出现问题。 默认情况下,mysql   它本身将分号识别为语句分隔符,因此您必须这样做   暂时重新定义分隔符以使mysql传递整个分隔符   存储的程序定义到服务器

DELIMITER //
CREATE FUNCTION isInArea(p POINT, poly POLYGON)
    RETURNS INT(1)
    DETERMINISTIC
    BEGIN
        DECLARE n INT DEFAULT 0;
        DECLARE pX DECIMAL(9, 6);
        DECLARE pY DECIMAL(9, 6);
        DECLARE ls LINESTRING;
        DECLARE poly1 POINT;
        DECLARE poly1X DECIMAL(9, 6);
        DECLARE poly1Y DECIMAL(9, 6);
        DECLARE poly2 POINT;
        DECLARE poly2X DECIMAL(9, 6);
        DECLARE poly2Y DECIMAL(9, 6);
        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//


DELIMITER ;