gpt4 book ai didi

mysql - 使用一个 in 和 int 参数创建 mysql 存储过程

转载 作者:行者123 更新时间:2023-11-29 17:20:17 24 4
gpt4 key购买 nike

    CREATE PROCEDURE SelectPetDetails
(
IN PetId int
)
BEGIN
SELECT * FROM pet p JOIN animal a on p.int_AnimalId=a.int_AnimalId JOIN breed b on a.int_BreedId=b.int_BreedId JOIN colorpattern c ON a.int_ColorPatternId=c.int_ColorPatternId WHERE int_PetOwnerId= PetId
END

我创建的存储过程出了什么问题?

最佳答案

要创建存储过程,您必须将默认分隔符 ; 更改为其他字符,例如“$$”或“//”或任何您想要的字符。

-- must change ; to $$ because stored procedure can have ; multiple times
DELIMITER $$
drop procedure if exists SelectPetDetails$$ -- if you plan execute this many times
CREATE PROCEDURE SelectPetDetails (IN PetId int)
BEGIN
SELECT * FROM pet p
JOIN animal a on p.int_AnimalId=a.int_AnimalId
JOIN breed b on a.int_BreedId=b.int_BreedId
JOIN colorpattern c ON a.int_ColorPatternId=c.int_ColorPatternId
WHERE int_PetOwnerId = PetId;
-- mark as end of stored procedure body
END $$

DELIMITER ;
-- return to regular delimiter

关于mysql - 使用一个 in 和 int 参数创建 mysql 存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51299251/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com