在DB-Fiddle中使用分隔符(MySQL 8.0)

时间:2019-03-23 14:37:20

标签: mysql sql mysql-8.0

我正在尝试在db-fiddle.com(https://www.db-fiddle.com/f/qMPGptFmKSNMJartC8yMfD/1)上创建一个存储过程,但是我很难弄清楚该如何处理我的DELIMITER语句。

我已经在Schema端构建了表和存储过程代码,并且试图从Query端调用存储过程。

DELIMITER //          
CREATE PROCEDURE conservation_count (IN con INT)
BEGIN
   DECLARE ytotal INT;
   SET ytotal := 0;
   SET ytotal := (SELECT COUNT(*) FROM Species, Animals
              WHERE Species.ID = Animals.species
              AND Species.ConservationStatus = con);
   SELECT ytotal;
   INSERT INTO conservation_ct VALUES (ytotal);
END //     
DELIMITER;

这是db-fiddle发回的架构错误:

Schema Error: Error: ER_PARSE_ERROR: 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' at line 10

1 个答案:

答案 0 :(得分:0)

因此,在进行了更多测试之后,发生了两件事:

  1. 我的上一个DELIMITER在DELIMITER和;之间需要一个空格。 -可能导致DELIMITER错误
  2. DB-Fiddle不喜欢我的存储过程。当我取出内部变量并将其简化时,它可以完美运行:

    DELIMITER //
    CREATE PROCEDURE conservation_count (IN var1 INT)
    BEGIN
    SELECT COUNT(*) FROM Species, Animals WHERE Species.ID = Animals.species 
    AND Species.ConservationStatus = var1 ;
    END //
    DELIMITER ;