if...条件...then
end if;
------------------
if...条件...then
语句1
else
语句2
end if;
-----------------
if...条件1...then
语句1
elsif...条件2...then
语句2
elsif...条件3...then
语句3
...........
end if;
--练习条件判断语句
--更新账户余额
--编写一个过程,输入一个账户名,如果该账户的余额低于100,就增加10%
create or replace procedure sp_money_test(sp_name in varchar2) as
--%TYPE
--引用某个变量或数据库列的数据库类型来声明变量。
v_money userinfo.leavmoney%type;
begin
select leavmoney into v_money from userinfo where loginname=sp_name;
if v_money<100 then
update userinfo set leavmoney=leavmoney*1.1 where loginname=sp_name;
end if;
end;
--对上面的过程进行条件判断扩展
create or replace procedure sp_money_test2(sp_name in varchar2) as
v_money userinfo.leavmoney%type;
begin
select leavmoney into v_money from userinfo where loginname=sp_name;
if v_money<10 then --like 7,8
update userinfo set leavmoney=leavmoney+1 where loginname=sp_name;
elsif v_money<20 then --like 12,19
update userinfo set leavmoney=leavmoney+2 where loginname=sp_name;
elsif v_money<50 then --like 22,32,45
update userinfo set leavmoney=leavmoney+5 where loginname=sp_name;
else --like 大于50
update userinfo set leavmoney=leavmoney+10 where loginname=sp_name;
end if;
end;