在 oracle pl/sql 中创建提款程序

create withdrawal procedure in oracle pl/sql

我想在 oracle 中创建提款程序 pl/sql。

我有这个table

ACCOUNT_NO BRANCH_NAME                                        AMOUNT_BALANCE
---------- -------------------------------------------------- --------------
       102 MA                                                      32900
       101 NA                                                      32000
       103 IA                                                      50000
       104 SA                                                      45000
       105 MSA                                                     20000

我尝试使用此代码

CREATE OR REPLACE  PROCEDURE withdrawal_proc IS

con  number(6);
con1 number(6);
bal1 number(20);
bal2 number(20);

begin

con := &con;
bal1 := &bal;

select Account_No, Amount_Balance into con1, bal2 from Accounts where Account_No=con;

if (bal2 < bal1)

dbms_output.put_line('the amount enterd is more than the amount balance');
else

update Accounts set Amount_Balance=(bal1-bal2) where con =con1;
end if; 

dbms_output.put_line('Money has been Withdraw succesfully');
END;
/

但是出现警告:创建的过程存在编译错误。

您不能在存储过程中使用 SQL*Plus 样式的变量,例如 &con&bal1。在这种情况下,conbal 值可能应该作为参数传递给过程:

CREATE OR REPLACE  PROCEDURE withdrawal_proc(account_no_in IN NUMBER(6),
                                             bal_in IN NUMBER(20))
IS
  current_balance number(20);
BEGIN
  select Amount_Balance
    into current_balance
    from Accounts
    where Account_No = account_no_in;

  if current_balance < bal_in then
   dbms_output.put_line('The amount entered is more than the amount balance');
  else
    update Accounts
      set Amount_Balance = bal_in - current_balance
      where Account_No = account_no_in;
  end if; 

  dbms_output.put_line('Money has been withdrawn successfully');
END;

您的 IF 语句也使用了不正确的语法 - 将原始代码与上面的版本进行比较。

另外请注意,我怀疑帐户余额计算可能不正确。您可能需要稍微调试一下。

祝你好运。