Return value from MySQL stored procedure

前端 未结 4 1467
北海茫月
北海茫月 2020-12-19 08:51

So I\'ve finally decided to get around to learning how to use stored procedures, and although I do have them working, I\'m unsure if I\'m doing it correctly - aka. the b

4条回答
  •  鱼传尺愫
    2020-12-19 09:28

    If you want this:

    DECLARE doesTagExist BOOL;
    SET doesTagExist = CheckTagExist('str');
    

    then you should use functions:

    DELIMITER //
     CREATE FUNCTION CheckTagExists(
       tagName VARCHAR(255)
     )
     BEGIN
       DECLARE doesTagExist BOOL;
    
     -- Check if tag exists
     SELECT
      EXISTS(
       SELECT
        *
       FROM
        tags
       WHERE
        tags.NAME = tagName
      )
     INTO
      doesTagExist;
    
      RETURN doesTagExist;
    END //
    DELIMITER ;
    

提交回复
热议问题