mysql while,loop,repeat循环,符合条件跳出循环,游标

DROP PROCEDURE IF EXISTS mywhile;
CREATE PROCEDURE mywhile ()
BEGIN
DECLARE i INT default 0;
outer_label: BEGIN  #设置一个标记并设置开始
while i<10 DO
SET i = i + 1;
IF i > 2 THEN
select '跳出循环' column1;
LEAVE  outer_label;  #满足条件,终止循环,跳转到end outer_label标记
ELSE
SELECT i as column1;
END IF;

end while;
END outer_label;  #设置标记并结束
END
call mywhile;




DROP PROCEDURE IF EXISTS myloop;

CREATE PROCEDURE myloop ()
BEGIN
DECLARE i INT default 0;


loop_label:LOOP#循环开始
SET i = i + 1;
IF i > 3 THEN
select '跳出循环' column1;
LEAVE loop_label;  #终止循环
ELSE
SELECT NOW() as column1;
END IF;
END LOOP;
ENd

call myloop;



DROP PROCEDURE IF EXISTS myrepeat;
CREATE PROCEDURE myrepeat ()
BEGIN
DECLARE i INT default 0;
REPEAT
SET i = i + 1;
until i>2 
end REPEAT;
END

call myrepeat;






DROP PROCEDURE IF EXISTS myCURSOR;
CREATE PROCEDURE myCURSOR ()
BEGIN
DECLARE user_name VARCHAR(32);


/* 声明游标 */
DECLARE my_cursor CURSOR FOR select nickname from users;


/* 打开游标 */
OPEN my_cursor;
sale_loop: LOOP
FETCH my_cursor INTO user_name;
select user_name;
END LOOP;
-- 关闭游标
close my_cursor;
end


call myCURSOR;

posted @   silentmuh  阅读(341)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
Live2D
欢迎阅读『mysql while,loop,repeat循环,符合条件跳出循环,游标』
  1. 1 Walk Thru Fire Vicetone
  2. 2 爱你 王心凌
  3. 3 Inspire Capo Productions - Serenity
  4. 4 Welcome Home Radical Face
  5. 5 粉红色的回忆 李玲玉
Walk Thru Fire - Vicetone
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

作词 : Van Der Voort, Joren Johannes

作曲 : Victor Pool/Justin Gammella/Ruben Christopher den Boer/Meron Mengist/Joren van der Voort

Talk to me

Spill the secrets you've been keeping

Life cuts deep

Let me help pick up the pieces

You're not alone, I'm by your side

Don't you know, don't you know

I'll walk through fire with you

I'll walk through fire

No matter what, I'll make it right

Don't you know, don't you know

I'll walk through fire with you

I'll walk through fire

I'm not an angel, I'm not a saint

I've been a closed book full of mistakes

But when you're broken, when you're in pain

Oooh, ooh

I'll walk through fire with you

I'll walk through fire

I'll walk through fire with you

I'll walk through fire

You know I

Don't pretend to be a savior

But let me in, yeah

I promise nobody can break us

You're not alone, I'm by your side

Don't you know, don't you know

I'll walk through fire with you

I'll walk through fire

No matter what, I'll make it right

Don't you know, don't you know

I'll walk through fire with you

I'll walk through fire

I'm not an angel, I'm not a saint

I've been a closed book full of mistakes

But when you're broken, when you're in pain

Oooh, ooh

I'll walk through fire with you

I'll walk through fire with you

I'll walk through fire

I'll walk through fire with you

I'll walk through fire with you

You're not alone, I'm by your side

Don't you know, don't you know

I'll walk through fire with you

I'll walk through fire

I'm not an angel, I'm not a saint

I've been a closed book full of mistakes

But when you're broken, when you're in pain

Oooh, ooh

I'll walk through fire with you

I'll walk through fire with you

I'll walk through fire

I'll walk through fire with you

I'll walk through fire with you

点击右上角即可分享
微信分享提示