From 7a90446071582d92dc3dccd19d19d6b0c78bad42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E5=AF=8C?= <2744975513@qq.com> Date: Tue, 10 Oct 2023 19:51:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... \345\260\217\344\275\234\344\270\232.txt" | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 "17 \345\221\250\345\257\214/20231010 \345\260\217\344\275\234\344\270\232.txt" diff --git "a/17 \345\221\250\345\257\214/20231010 \345\260\217\344\275\234\344\270\232.txt" "b/17 \345\221\250\345\257\214/20231010 \345\260\217\344\275\234\344\270\232.txt" new file mode 100644 index 0000000..84d4c38 --- /dev/null +++ "b/17 \345\221\250\345\257\214/20231010 \345\260\217\344\275\234\344\270\232.txt" @@ -0,0 +1,86 @@ +-- 写一个存储过程,可以输入一个整数,输入小于或等于0时,提示非法输入,并中止这个存储过程, +-- 否则先判断这个数和是不是大于20,如果大于20就从1循环到这个数,并找出所有的偶数(但遇到逢10的数要跳过)。小于等于20就提示数太小了,并退出。 + +-- 要求,循环部分,要用三种语法分别做一遍 + +~~~mysql +-- 写一个存储过程,可以输入一个整数,输入小于或等于0时,提示非法输入,并中止这个存储过程, +-- 否则先判断这个数和是不是大于20,如果大于20就从1循环到这个数,并找出所有的偶数(但遇到逢10的数要跳过)。小于等于20就提示数太小了,并退出。 + +-- 要求,循环部分,要用三种语法分别做一遍 +#whlie +drop procedure xx; +delimiter // +CREATE procedure xx(in num int) +a:BEGIN +declare i int DEFAULt 1; + if num<=0 then + SELECT "非法输入"; + leave a; + elseif num > 20 then + b:while i<=num do + if i%2=1 or i%10=0 then set i = i+1; + iterate b ; + end if; + SELECT i; + set i = i+1; + end while b; + else SELECT "数太小了"; + leave a; +end if; +end // +delimiter ; +call xx (50) + +#loop +drop procedure zz; +delimiter // +CREATE procedure zz(in num int) +a:BEGIN +declare i int DEFAULt 1; + if num<=0 then + SELECT "非法输入"; + leave a; + elseif num > 20 then + b:loop + if i%2=1 or i%10=0 then set i = i+1; + iterate b ; + end if; + if i>num then leave b; + end if; + SELECT i; + set i = i+1; + end loop b; + else SELECT "数太小了"; + leave a; +end if; +end // +delimiter ; +call zz (50) +#repeat +drop procedure ff; +delimiter // +CREATE procedure ff(in num int) +a:BEGIN +declare i int DEFAULt 1; + if num<=0 then + SELECT "非法输入"; + leave a; + elseif num > 20 then + b:repeat + if i%2=1 or i%10=0 then set i = i+1; + iterate b ; + else SELECT i; + end if; + set i = i+1; + UNTIL i>num + end repeat b; + + else SELECT "数太小了"; + leave a; +end if; +end // +delimiter ; +call ff (100) +~~~ + -- Gitee