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/ ,如需转载,请注明出处,否则将追究法律责任。