我正在尝试在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
答案 0 :(得分:0)
因此,在进行了更多测试之后,发生了两件事:
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 ;