mysql存储过程失败' END'

时间:2016-03-23 10:01:02

标签: mysql stored-procedures

我无法理解为什么这样做不会起作用,我有一个近似类似的程序,可以毫无问题地工作,但是这个程序只会引发错误:

  

#1064 - 您的SQL语法出错;检查手册   对应于您的MySQL服务器版本,以便使用正确的语法   靠近' END'在第36行

  DELIMITER //
CREATE PROCEDURE FillCnsGroupWithRates
(
    IN groupId INT(10)
)
BEGIN
    SET @var1 = groupId;
    INSERT INTO 
        cns_group_rates 
        (
            cns_id,
            other_cns_id,
            ppc,
            pps,
            max_price,
            notes,
            cns_group_id
        )
    SELECT 
        cns_id,
        other_cns_id,
        ppc,
        pps,
        max_price,
        notes,
        @var1
    FROM 
        cns_rates
    WHERE 
        cns_id NOT LIKE '319%'
    AND
        client_id IS NULL
    AND
        subordinates IS NULL
    AND
        valid_from IS NULL
END //
DELIMITER ;

2 个答案:

答案 0 :(得分:1)

你忘记了结尾的分号

DELIMITER //
CREATE PROCEDURE FillCnsGroupWithRates
(
    IN groupId INT(10)
)
BEGIN
    SET @var1 = groupId;
    INSERT INTO 
        cns_group_rates 
        (
            cns_id,
            other_cns_id,
            ppc,
            pps,
            max_price,
            notes,
            cns_group_id
        )
    SELECT 
        cns_id,
        other_cns_id,
        ppc,
        pps,
        max_price,
        notes,
        @var1
    FROM 
        cns_rates
    WHERE 
        cns_id NOT LIKE '319%'
    AND
        client_id IS NULL
    AND
        subordinates IS NULL
    AND
        valid_from IS NULL;
END //
DELIMITER ;

答案 1 :(得分:0)

您在查询结束时忘记了分号 试试这个

DELIMITER //
CREATE PROCEDURE FillCnsGroupWithRates
(
    IN groupId INT(10)
)
BEGIN
    SET @var1 = groupId;
    INSERT INTO 
        cns_group_rates 
        (
            cns_id,
            other_cns_id,
            ppc,
            pps,
            max_price,
            notes,
            cns_group_id
        )
    SELECT 
        cns_id,
        other_cns_id,
        ppc,
        pps,
        max_price,
        notes,
        @var1
    FROM 
        cns_rates
    WHERE 
        cns_id NOT LIKE '319%'
    AND
        client_id IS NULL
    AND
        subordinates IS NULL
    AND
        valid_from IS NULL;
END //
DELIMITER ;