【问题标题】:MYSQL server error when create a function创建函数时MYSQL服务器错误
【发布时间】:2015-02-07 02:05:05
【问题描述】:

当我运行查询时,我有一个函数而不是我得到这个错误

创建函数 createBuffer( 浮桥点, 距离INT ) RETURNS POLYGON BEGIN /** * * @description : 以米为单位围绕给定点和半径创建一个圆的函数 * @author : Fernando Norte (fnorte at gmail dot com) * * @params : ponto POINT (geometry), distancia INT (以米为单位) * @return : Polygon (geometry) * **/ SET @angle =0;

MySQL 说:文档

1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 13 行的 '' 附近使用正确的语法

DROP FUNCTION IF EXISTS createBuffer;
CREATE FUNCTION createBuffer(tragetPoint POINT, distance INT) RETURNS POLYGON

    BEGIN
    /**
     *
     * @description : Function to create a circle around a given point and a radius in meters
     * @author : Fernando Norte (fnorte at gmail dot com)
     *
     * @params : tragetPoint POINT (geometry), distance INT (in meters)
     * @return : Polygon (geometry)
     *
     **/
        SET @angle = 0; 
        SET @buffer = ''; # point collection string
        SET @firstPoint = ''; # to close to polygon 
        SET @xP = X(tragetPoint);  # Lat of given point
        SET @yP = Y(tragetPoint); # Long of given point
        SET @radius = (distance / 111200); # Conversion from meters to decimal degres (number to confirm)

        REPEAT
            # Algorithm to put the points around the center
            SET @Nx = @xP + @radius * COS(@angle);  
            SET @Ny = @yP + @radius * SIN(@angle);

            # Concatenate the border point X,Y to the buffer string
            SET @buffer = CONCAT(@buffer, @Nx, ' ', @Ny, ', ');

            IF @angle = 0 THEN 
                # reserve the first point collected to close the polygon
                SET @firstPoint = CONCAT(@Nx, ' ', @Ny); 
            END IF;
            SET @angle = @angle + (2*PI()/20); # increment angle to put 20 points around the center
        UNTIL @angle >= (2*PI()) END REPEAT;

        # create WKT for the Polygon
        SET @buffer = CONCAT('POLYGON((', @buffer, @firstPoint, '))');

        RETURN GeomFromText(@buffer); 

    END

我无法理解发生了什么

【问题讨论】:

  • 一些局部变量没有声明..
  • 角度、缓冲区、firstPoint、xP、yP...
  • 只设置为可验证
  • 你改变了分隔符吗?

标签: mysql mysql-error-1064


【解决方案1】:

这对我有用,测试是数据库的名称。

use test;
DELIMITER $$

CREATE FUNCTION createBuffer(tragetPoint POINT, distance INT) RETURNS POLYGON
DETERMINISTIC
    BEGIN
    /**
     *
     * @description : Function to create a circle around a given point and a radius in meters
     * @author : Fernando Norte (fnorte at gmail dot com)
     *
     * @params : tragetPoint POINT (geometry), distance INT (in meters)
     * @return : Polygon (geometry)
     *
     **/

        SET @angle = 0; 
        SET @buffer = ''; # point collection string
        SET @firstPoint = ''; # to close to polygon 
        SET @xP = X(tragetPoint);  # Lat of given point
        SET @yP = Y(tragetPoint); # Long of given point
        SET @radius = (distance / 111200); # Conversion from meters to decimal degres (number to confirm)

        REPEAT
            # Algorithm to put the points around the center
            SET @Nx = @xP + @radius * COS(@angle);  
            SET @Ny = @yP + @radius * SIN(@angle);

            # Concatenate the border point X,Y to the buffer string
            SET @buffer = CONCAT(@buffer, @Nx, ' ', @Ny, ', ');

            IF @angle = 0 THEN 
                # reserve the first point collected to close the polygon
                SET @firstPoint = CONCAT(@Nx, ' ', @Ny); 
            END IF;
            SET @angle = @angle + (2*PI()/20); # increment angle to put 20 points around the center
        UNTIL @angle >= (2*PI()) END REPEAT;

        # create WKT for the Polygon
        SET @buffer = CONCAT('POLYGON((', @buffer, @firstPoint, '))');

        RETURN GeomFromText(@buffer); 

    END$$
    DELIMITER ;

MySQL CREATE FUNCTION Syntax

【讨论】:

    猜你喜欢
    • 2011-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-13
    • 2019-03-25
    • 1970-01-01
    • 1970-01-01
    • 2022-07-05
    相关资源
    最近更新 更多