ITPub博客

首页 > 数据库 > Oracle > 银行转账简易功能

银行转账简易功能

原创 Oracle 作者:Latte_oracle 时间:2020-02-16 13:53:29 0 删除 编辑

create or replace procedure account_transfer(

amount in int,v_ano char,vv_ano char)

as

var_balance int;

begin

if v_ano='B00' then

select balance into var_balance from account where ano='B00';

elsif v_ano='A00' then

select balance into var_balance from account where ano='A00';

else

select balance into var_balance from account where ano='C00';

end if;

IF var_balance-amount<0 then

dbms_output.put_line('金额不足,不能转账!');

rollback;            --回退事务

 return;                --跳过case

 end if;

case vv_ano 

when 'A00' then 

update account set balance=balance+amount where ano='A00';

when 'B00' then 

update account set balance=balance+amount where ano='B00';

else update account set balance=balance+amount where ano='C00';

end case;

case v_ano 

when 'A00' then 

update account set balance=balance-amount where ano='A00';

when 'B00' then 

update account set balance=balance-amount where ano='B00';

else update account set balance=balance-amount where ano='C00';

end case;

commit;            --提交事务

 dbms_output.put_line('提交成功,正常转账');

end;

 /


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69961142/viewspace-2675761/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2020-02-14

  • 博文量
    1
  • 访问量
    229