mysql存储过程中while和if语句

mysql存储过程中while和if语句
CREATE DEFINER=`root`@`%` PROCEDURE `CheckNumbers`()
BEGIN
DECLARE counter INT DEFAULT 1;
DECLARE max_limit INT DEFAULT 10;

-- WHILE 循环
WHILE counter <= max_limit DO
-- IF 判断
IF counter % 2 = 0 THEN
-- 如果是偶数
SELECT CONCAT(counter, ' 是偶数');
ELSE
-- 如果是奇数
SELECT CONCAT(counter, ' 是奇数');
END IF;

-- 增加计数器
SET counter = counter + 1;
END WHILE;
END

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: