【问题标题】:Stored procedure for money transfer in PLSQLPLSQL中转账的存储过程
【发布时间】:2022-10-22 18:22:04
【问题描述】:

希望这个任务能找到你。

Please help me out with this,

My requirement is to transfer money from one account to another account which is in a same table.
the procedure should have 3 in parameters,
They are,
--> from_account_number
--> To_account_number
--> Credit_amount

实际数据:

acc_num        acc_bal
12345          50000
67890          40000

预期数据:

eg: exec trans_sp(12345,67890,10000);
ac_num   ac_bal
12345    40000
67890    60000
`trans_sp`

【问题讨论】:

  • 从一个帐户中减去并添加到另一个帐户;应该相当简单。试试看。

标签: oracle stored-procedures plsql plsql-package


【解决方案1】:

一个简单的选项(根本没有控件;自己添加):

前:

SQL> select * from money;

ACCOUNT_NU     AMOUNT
---------- ----------
12345           10000
65789           20000
86420           30000

程序:

SQL> create or replace procedure trans_sp (par_acc_from in varchar2, par_acc_to in varchar2, par_amount in number)
  2  is
  3  begin
  4    update money set
  5      amount = amount - par_amount
  6      where account_number = par_acc_from;
  7
  8    update money set
  9      amount = amount + par_amount
 10      where account_number = par_acc_to;
 11  end;
 12  /

Procedure created.

测试:

SQL> exec trans_sp('86420', '12345', 5000);

PL/SQL procedure successfully completed.

后:

SQL> select * from money;

ACCOUNT_NU     AMOUNT
---------- ----------
12345           15000
65789           20000
86420           25000

SQL>

【讨论】:

    猜你喜欢
    • 2015-04-01
    • 1970-01-01
    • 2011-01-24
    • 2018-12-28
    • 1970-01-01
    • 1970-01-01
    • 2017-12-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多