mysql out模式的存儲過程

#案例:根據女神名,返回對應的男神名ide

DELIMITER $
CREATE PROCEDURE myp5(IN beautyName VARCHAR(20),OUT boyName VARCHAR(20))
BEGIN
    SELECT bo.boyName INTO boyName
    FROM boys bo
    INNER JOIN beauty b ON bo.id=b.boyfriend_id
    WHERE b.name=beautyName;
END $

#調用code

SET @bName $ 
CALL myp5('小昭',@bName) $
SELECT @bName $
或

CALL myp5('小昭',@bName)$
SELECT @bName$

#案例:根據女神名,返回對應的男神名和男神魅力值it

CREATE PROCEDURE myp6(IN beautyName VARCHAR(20),OUT boyName VARCHAR(20),OUT userCp INT)
BEGIN
    SELECT bo.boyName ,bo.userCp INTO boyName,userCP
    FROM boys bo
    INNER JOIN beauty b ON bo.id=b.boyfriend_id
    WHERE b.name=beautyName;

END $

#調用class

CALL myp6('小昭',@bName,@usercp)$
SELECT @bName,@usercp$
相關文章
相關標籤/搜索