#案例:根据女神名,返回对应的男神名
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$