流程控制
- 顺序结构: 程序从上往下依次执行
 - 分支结构: 程序按条件进行选择执行,从两条或多条路径中选择一条执行。
 - 循环结构: 程序满足一定条件下,重复执行一组语句
 
针对于MySQL的流程控制语句主要有3类。注意:只能用于存储程序
条件判断语句 :if 语句 和 case 语句
循环语句:LOOP、while、REPEAT
分支结构 if elseif end if



if 语句语法结构
if 表达式1 then 
操作1
[elseif  表达式2 then 操作2].。。。
[else 操作n]
end if  ;   --这个  ;  别忘记了
        案例
delimiter $
create procedure pro_x(in id)
begin
	declare dep_id , emp_id int ;
	declare work_age int default 1;
	select  depid , workage , empid   into dep_id  , workage , empid  
	from  emp
	where emp_id=id ;
	# if   分支
	if  work_age >=20 and dep_id =1002 then
	  # 操作语句;
	elseif if  dep_id =1004 then
	  # 操作语句;
	else   #  else  后面没有  then
	# 操作语句;
	end if  ;   #   end if ;  别忘记
end $
delimiter ;
###   调用 存储过程
set @id=10;
call  pro_x(@id);
        
分支结构 case when then
跟在 select 中 case when then 一样的
**syntax **
##  情况1   :  类似  switch  case 
case 表达式
when 值1 then  操作
when 值2 then  操作
。。。。
else   结构n 或语句n(如果是语句,需要加  分号 )
 end [case] (如果是放在begin end 中需要加上 case,如果放在select 后面不需要)
### 情况2   类似   if
case 
when   表达式1   then   操作
when   表达式 2  then   操作
。。。。
else 结果 n 或语句你如果是语句,需要加  分号 )
 end [case] (如果是放在begin end 中需要加上 case,如果放在select 后面不需要)
        
循环结构 之 LOOP
[ loop_label : ] LOOP
    循环执行的语句
end loop [ loop_label]
# 其中,Loop_label 表示Lopp语句的标注名称,该参数可以省略
        案例
delimiter $
create procedure pro_loop(out cnt int )
begin
	declare id int default 0;
	add_loop : LOOP
			set id =id +1;
			if cnt>=10 then
				LEAVE add_loop;
			end if;
	 END LOOP add_loop;
	 set cnt=id;
end $
 delimiter ;
####  调用 
call pro_loop( @num)