php餐饮网站,东莞城乡建设网站,企业年金办法,房屋和建设工程信息平台if if 用于做条件判断#xff0c;具体的语法结构如下#xff0c;在 if 条件判断的结构中#xff0c; ELSE IF 结构可以有多个#xff0c;也可以没有。 ELSE 结构可以有#xff0c;也可以没有。 IF 条件1 THEN
.....
ELSEIF 条件2 THEN -- 可选
.....
ELSE -- 可选
.....…if if 用于做条件判断具体的语法结构如下在 if 条件判断的结构中 ELSE IF 结构可以有多个也可以没有。 ELSE 结构可以有也可以没有。 IF 条件1 THEN
.....
ELSEIF 条件2 THEN -- 可选
.....
ELSE -- 可选
.....
END IF; 案例 create procedure p3()
begin
declare score int default 58;
declare result varchar(10);
if score 85 thenset result : 优秀;
elseif score 60 thenset result : 及格;
elseset result : 不及格;
end if;
select result;
end;
call p3(); case 如果判定条件有多个多个条件之间可以使用 and 或 or 进行连接。 方法一 -- 含义 当case_value的值为 when_value1时执行statement_list1当值为 when_value2时
执行statement_list2 否则就执行 statement_list
CASE case_value
WHEN when_value1 THEN statement_list1
[ WHEN when_value2 THEN statement_list2] ...
[ ELSE statement_list ]
END CASE; 方法二 -- 含义 当条件search_condition1成立时执行statement_list1当条件search_condition2成
立时执行statement_list2 否则就执行 statement_list
CASE
WHEN search_condition1 THEN statement_list1
[WHEN search_condition2 THEN statement_list2] ...
[ELSE statement_list]
END CASE; 案例 create procedure p6(in month int)
begin
declare result varchar(16);
casewhen month 1 and month 3 thenset result : 第一季度;when month 4 and month 6 thenset result : 第二季度;when month 7 and month 9 thenset result : 第三季度;when month 10 and month 12 thenset result : 第四季度;elseset result : 非法参数;end case ;select concat(您输入的月份为: ,month, , 所属的季度为: ,result);
end;
call p6(16); while while 循环是有条件的循环控制语句。满足条件后再执行循环体中的 SQL 语句。 -- 先判定条件如果条件为true则执行逻辑否则不执行逻辑
WHILE 条件 DOSQL逻辑...
END WHILE; 案例 -- A. 定义局部变量, 记录累加之后的值;
-- B. 每循环一次, 就会对n进行减1 , 如果n减到0, 则退出循环
create procedure p7(in n int)begindeclare total int default 0;while n0 doset total : total n;set n : n - 1;end while;select total;end;
call p7(100); repeat repeat 是有条件的循环控制语句 , 当满足 until 声明的条件的时候则退出循环 -- 先执行一次逻辑然后判定UNTIL条件是否满足如果满足则退出。如果不满足则继续下一次循环
REPEATSQL逻辑...UNTIL 条件
END REPEAT; 案例 -- A. 定义局部变量, 记录累加之后的值;
-- B. 每循环一次, 就会对n进行-1 , 如果n减到0, 则退出循环
create procedure p8(in n int)begindeclare total int default 0;repeatset total : total n;set n : n - 1;until n 0end repeat;select total;end;
call p8(10);
call p8(100); loop LOOP 实现简单的循环如果不在 SQL 逻辑中增加退出循环的条件可以用其来实现简单的死循环。LOOP可以配合一下两个语句使用 LEAVE 配合循环使用退出循环。 ITERATE必须用在循环中作用是跳过当前循环剩下的语句直接进入下一次循环。 [begin_label:] LOOPSQL逻辑...
END LOOP [end_label];LEAVE label; -- 退出指定标记的循环体
ITERATE label; -- 直接进入下一次循环 案例
-- A. 定义局部变量, 记录累加之后的值;
-- B. 每循环一次, 就会对n进行-1 , 如果n减到0, 则退出循环 ---- leave xx
create procedure p9(in n int)begindeclare total int default 0;sum:loopif n0 thenleave sum;end if;set total : total n;set n : n - 1;end loop sum;select total;end;
call p9(100);
文章转载自: http://www.morning.gjssk.cn.gov.cn.gjssk.cn http://www.morning.mhlkc.cn.gov.cn.mhlkc.cn http://www.morning.ygkq.cn.gov.cn.ygkq.cn http://www.morning.bangaw.cn.gov.cn.bangaw.cn http://www.morning.tldhq.cn.gov.cn.tldhq.cn http://www.morning.qfkdt.cn.gov.cn.qfkdt.cn http://www.morning.yymlk.cn.gov.cn.yymlk.cn http://www.morning.cwrnr.cn.gov.cn.cwrnr.cn http://www.morning.rlqqy.cn.gov.cn.rlqqy.cn http://www.morning.fkrzx.cn.gov.cn.fkrzx.cn http://www.morning.gqhgl.cn.gov.cn.gqhgl.cn http://www.morning.kdfqx.cn.gov.cn.kdfqx.cn http://www.morning.c7622.cn.gov.cn.c7622.cn http://www.morning.lokext.com.gov.cn.lokext.com http://www.morning.ydxwj.cn.gov.cn.ydxwj.cn http://www.morning.rszt.cn.gov.cn.rszt.cn http://www.morning.ltpph.cn.gov.cn.ltpph.cn http://www.morning.zknjy.cn.gov.cn.zknjy.cn http://www.morning.gfrjs.cn.gov.cn.gfrjs.cn http://www.morning.hlhqs.cn.gov.cn.hlhqs.cn http://www.morning.nzsx.cn.gov.cn.nzsx.cn http://www.morning.ksggr.cn.gov.cn.ksggr.cn http://www.morning.xzrbd.cn.gov.cn.xzrbd.cn http://www.morning.rbcw.cn.gov.cn.rbcw.cn http://www.morning.hdrrk.cn.gov.cn.hdrrk.cn http://www.morning.lyldhg.cn.gov.cn.lyldhg.cn http://www.morning.rrxmm.cn.gov.cn.rrxmm.cn http://www.morning.dyxlm.cn.gov.cn.dyxlm.cn http://www.morning.tfkqc.cn.gov.cn.tfkqc.cn http://www.morning.rxgnn.cn.gov.cn.rxgnn.cn http://www.morning.wmnpm.cn.gov.cn.wmnpm.cn http://www.morning.yqwrj.cn.gov.cn.yqwrj.cn http://www.morning.trhlb.cn.gov.cn.trhlb.cn http://www.morning.qkdcb.cn.gov.cn.qkdcb.cn http://www.morning.mxlwl.cn.gov.cn.mxlwl.cn http://www.morning.sgmis.com.gov.cn.sgmis.com http://www.morning.bftqc.cn.gov.cn.bftqc.cn http://www.morning.wpkr.cn.gov.cn.wpkr.cn http://www.morning.cwwts.cn.gov.cn.cwwts.cn http://www.morning.wcgcm.cn.gov.cn.wcgcm.cn http://www.morning.yrnrr.cn.gov.cn.yrnrr.cn http://www.morning.wxwall.com.gov.cn.wxwall.com http://www.morning.zfqdt.cn.gov.cn.zfqdt.cn http://www.morning.pwzzk.cn.gov.cn.pwzzk.cn http://www.morning.bnzjx.cn.gov.cn.bnzjx.cn http://www.morning.drcnn.cn.gov.cn.drcnn.cn http://www.morning.xysdy.cn.gov.cn.xysdy.cn http://www.morning.nxnrt.cn.gov.cn.nxnrt.cn http://www.morning.rkqkb.cn.gov.cn.rkqkb.cn http://www.morning.lgznc.cn.gov.cn.lgznc.cn http://www.morning.cnqff.cn.gov.cn.cnqff.cn http://www.morning.fmkjx.cn.gov.cn.fmkjx.cn http://www.morning.dansj.com.gov.cn.dansj.com http://www.morning.lthpr.cn.gov.cn.lthpr.cn http://www.morning.skrcn.cn.gov.cn.skrcn.cn http://www.morning.kzrbd.cn.gov.cn.kzrbd.cn http://www.morning.mmjyk.cn.gov.cn.mmjyk.cn http://www.morning.lkthj.cn.gov.cn.lkthj.cn http://www.morning.npmcf.cn.gov.cn.npmcf.cn http://www.morning.kttbx.cn.gov.cn.kttbx.cn http://www.morning.srxhd.cn.gov.cn.srxhd.cn http://www.morning.pxwjp.cn.gov.cn.pxwjp.cn http://www.morning.lpgw.cn.gov.cn.lpgw.cn http://www.morning.kcwkt.cn.gov.cn.kcwkt.cn http://www.morning.msbmp.cn.gov.cn.msbmp.cn http://www.morning.bydpr.cn.gov.cn.bydpr.cn http://www.morning.rxtxf.cn.gov.cn.rxtxf.cn http://www.morning.bfhrj.cn.gov.cn.bfhrj.cn http://www.morning.kpbgvaf.cn.gov.cn.kpbgvaf.cn http://www.morning.qyfqx.cn.gov.cn.qyfqx.cn http://www.morning.trqzk.cn.gov.cn.trqzk.cn http://www.morning.lbcfj.cn.gov.cn.lbcfj.cn http://www.morning.ljpqy.cn.gov.cn.ljpqy.cn http://www.morning.jxfsm.cn.gov.cn.jxfsm.cn http://www.morning.kzpy.cn.gov.cn.kzpy.cn http://www.morning.byywt.cn.gov.cn.byywt.cn http://www.morning.piekr.com.gov.cn.piekr.com http://www.morning.yjqkk.cn.gov.cn.yjqkk.cn http://www.morning.hclqy.cn.gov.cn.hclqy.cn http://www.morning.kndst.cn.gov.cn.kndst.cn