为什么这个查询没有执行?

时间:2011-11-03 13:33:34

标签: mysql sql

DELIMITER $$

USE `horizon_jake`$$

DROP FUNCTION IF EXISTS `GPS_Distance_Meters`$$

CREATE DEFINER=`horizon_jake`@`localhost` FUNCTION `GPS_Distance_Meters`(lat1 DOUBLE, lng1 DOUBLE, lat2 DOUBLE, lng2 DOUBLE) RETURNS DOUBLE
BEGIN
    DECLARE rlo1 DOUBLE;
    DECLARE rla1 DOUBLE;
    DECLARE rlo2 DOUBLE;
    DECLARE rla2 DOUBLE;
    DECLARE dlo DOUBLE;
    DECLARE dla DOUBLE;
    DECLARE a DOUBLE;

    SET rlo1 = RADIANS(lng1);
    SET rla1 = RADIANS(lat1);
    SET rlo2 = RADIANS(lng2);
    SET rla2 = RADIANS(lat2);
    SET dlo = (rlo2 - rlo1) / 2;
    SET dla = (rla2 - rla1) / 2;
    SET a = SIN(dla) * SIN(dla) + COS(rla1) * COS(rla2) * SIN(dlo) * SIN(dlo);
    RETURN (6378137 * 2 * ATAN2(SQRT(a), SQRT(1 - a)));
END$$

DELIMITER ;

数据库名称:horizo​​n_jake
数据库用户:horizo​​n_jake

MySQL版本:5.1.56

错误消息

Error

SQL query:

DELIMITER $$ USE `horizon_jake` $$ DROP FUNCTION IF EXISTS `GPS_Distance_Meters` $$ CREATE DEFINER = `horizon_jake`@`localhost` FUNCTION `GPS_Distance_Meters` (
lat1 DOUBLE,
lng1 DOUBLE,
lat2 DOUBLE,
lng2 DOUBLE
) RETURNS DOUBLE BEGIN DECLARE rlo1 DOUBLE;

MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER $$

    USE `horizon_jake`$$

    DROP FUNCTION IF EXISTS ' at line 1 

1 个答案:

答案 0 :(得分:0)

DELIMITER定义SQL语句的分隔符。 USE不是SQL语句,因此不需要与$$分隔。