Mysql函数错误 - 无法弄清楚

时间:2014-01-06 04:21:19

标签: mysql mysql-workbench

请帮我解决Mysql功能。代码:

DELIMITER $$

CREATE FUNCTION `media`.`Return_Next_Season`(
        season VARCHAR(200) )
    RETURNS VARCHAR
    DECLARE _ids INT ;
    DECLARE _bsk VARCHAR(200);


SELECT id INTO _ids  FROM media._broadcast_seasons WHERE broadcast_season_key = '20132014_Fall';



SELECT broadcast_season_key INTO bsk FROM media._broadcast_seasons WHERE id  = ids;

    RETURN bsk;
    BEGIN

    END$$

DELIMITER ;

1 个答案:

答案 0 :(得分:0)

你认为在所有执行某些有用的代码之后BEGIN 是一个好主意吗? :-)或者,用较为迟钝的语言,将BEGIN移到RETURNS VARCHAR之后,类似(select语句为了可读性而分解,但您可能需要重新组合它们):< / p>

DELIMITER $$
CREATE FUNCTION `media`.`Return_Next_Season`(
    season VARCHAR(200) )
    RETURNS VARCHAR(200)
    BEGIN
        DECLARE _ids INT ;
        DECLARE _bsk VARCHAR(200);
        SELECT id INTO _ids  FROM media._broadcast_seasons
            WHERE broadcast_season_key = '20132014_Fall';
        SELECT broadcast_season_key INTO bsk FROM media._broadcast_seasons
            WHERE id  = ids;
        RETURN bsk;
    END$$
DELIMITER ;

您会注意到我也改变了返回类型,因为我认为这也是必要的。