1. 流程控制结构
循序结构: 程序从上往下 一次执行分支结构: 程序从两条 或 多条路径中 选择一条去执行循环结构: 程序满足一定条件 的基础上 , 重复执行一段代码0: false1: true
if 函数
格式:
//当boolean等于true时,返回str1,否则返回str2
if(boolean,str1,str2)
if(sex=1,'男','女')
case函数
格式:
case 参数
when 参数1 then 需要返回的值1
when 参数2 then 需要返回的值2
..
else 需要返回的值n
end
解释:
当参数等于参数1时候,返回值1
当参数等于参数2时候,返回值2
否则返回值n
end(结束)
select
case `user_name`
when 1 then '经理'
when 2 then '老板'
when 3 then '主管'
else '普通员工'
end
if 结构
格式:
if 条件1 then 语句1;
elseif 条件2 then 语句2;
.....
end if;
注意:
应用在 begin end 中
create function myf7(num int(10)) returns char
begin
if num<60 then return 'C';
elseif num>=60 and num<80 then return 'B';
elseif num>=80 and num<=100 then return 'A';
end if;
end
select myf7(79)