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

bihw5rsg  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(415)
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

我创建存储过程有什么问题?

pu82cl6c

pu82cl6c1#

要创建存储过程,必须更改默认分隔符 ; 另一个字符,如“$$”或“//”或任何你想要的字符。

-- 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

相关问题