Condional looping in mysql

Condional looping in mysql

恋你朝朝暮暮 发布于 2021-11-24 字数 541 浏览 855 回复 1 原文

Inside MySQL I have written a Procedure where I want to run a loop like this:

While (Cond) Do
  ...(Body1)
  ...
  If (Condition2)
    continue ;

  ...(Body2)
  ...
end while ;

Under the while loop I want the full body to run in case where Condition2 is not met (ie Body1 and Body2).

Currently, when Condition 2 is met, it just executes Body1 and then continues(Check Cond in While and Continue looping.)

Can someone help with the proper syntax to perform the above?

如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。

扫码加入群聊

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慈悲佛祖 2022-06-07 1 楼
BEGIN
    WHILE cond1 DO
        CALL body1;
        IF (NOT cond2) THEN
            CALL body2;
        END IF;
    END WHILE;
END;