mysql out模式的存储过程

#案例:根据女神名,返回对应的男神名

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 $

#调用

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

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

#案例:根据女神名,返回对应的男神名和男神魅力值

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 $

#调用

CALL myp6('小昭',@bName,@usercp)$
SELECT @bName,@usercp$
    原文作者:wx5d21d5e6e5ab1
    原文地址: https://blog.51cto.com/14437184/2440906
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞