【MySQL】MySQL PLSQL Demo - 006.循环(WHILE DO and FOR LOOP)

WHILE DO

复制代码
drop procedure if exists p_while_do;

create procedure p_while_do()
begin
    declare i int;
        set i = 1;
        while i <= 10 do
            select concat('index : ', i);
            set i = i + 1;
        end while;
end;

call p_while_do();
复制代码

 

FOR LOOP

复制代码
drop procedure if exists p_for_loop;

create procedure p_for_loop()
begin
    declare i int;
        set i = 1;
        loop_example : loop
            select concat('index -> ', i);
            set i = i + 1;

            if i > 10 then
                leave loop_example;
            end if;
        end loop;
end;

call p_for_loop();
复制代码

 

posted @   nick_huang  阅读(1008)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· Ollama——大语言模型本地部署的极速利器
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· Windows编程----内核对象竟然如此简单?
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
历史上的今天:
2014-09-12 【快速查阅】SQLPLUS连接ORACLE
点击右上角即可分享
微信分享提示