if函数

功能:实现简单的双分支

  1. if(表达式1,表达式2,表达式3)

执行顺序:
如果表达式1成立,则if函数返回表达式2,否则返回表达式3的值

if结构

功能:实现多重分支
语法:

if 条件1 then 语句1;
elseif 条件2 then 语句2
...
else 语句
end if

应用在begin end 中

案例1

create function test_if(score int ) return char 
begin 
    if score >=90 and score<=100 then return 'A';
    elseif score >=80 then return 'B';
    elseif score >=60 then return 'C';
    else return 'D';
    end if;
end $