一、结构
1.只有if模块,最简单的结构
if 条件 then
代码
end if;
2.if..else
if 条件 then
代码1
else
代码2
end if;
3.if..elsif/elseif..else..
if 条件1 then
代码1
elseif/elsif 条件2
代码2
...
else
代码n
end if;
二、举例
写一个存储过程,利用if语句判断考试成绩在90-100的评为优秀等级,60-90的评为合格等级,60以下的评为不合格等级。
create or replace procedure pro_grade(grade in double)
as
begin
if grade between 90 and 100 then
print ('优秀');
elseif grade between 60 and 90 then
print('合格');
elseif grade between 0 and 60 then
print ('不合格');
else
print('输入的成绩不符合要求');
end if;
EXCEPTION WHEN OTHERS THEN NULL;
end;
call pro_grade(60);结果:合格