不带参数
DELIMITER $$
USE `bookshop`$$
DROP PROCEDURE IF EXISTS `test2`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `test2`()
BEGIN
DECLARE num INT DEFAULT 5;
DECLARE stuTotal INT;
#赋值
SET num=10;
SET num=num+2;
#赋值
SELECT COUNT(*) INTO stuTotal FROM users;
SELECT num,stuTotal;
END$$
DELIMITER ;
带参数
成绩等级查询
DELIMITER $$
USE `bookshop`$$
DROP PROCEDURE IF EXISTS `test3`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `test3`(IN score INT,OUT description VARCHAR(10))
BEGIN
IF score>90 THEN SET description="优秀";
ELSEIF score>80 THEN SET description="良好";
ELSE SET description="一般";
END IF;
END$$
DELIMITER ;
|