我想在oracle pl / sql中创建一个提款程序。
我有这张桌子
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;
/
但是有一个警告:使用编译错误创建过程。
答案 0 :(得分:1)
您不能在存储过程中使用SQL * Plus样式的变量,例如&con
和&bal1
。在这种情况下,con
和bal
值可能应作为参数传递给过程:
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语句语法 - 将原始代码与上述版本进行比较。
另外,请注意我怀疑帐户余额计算可能不正确。您可能需要稍微调试一下。
祝你好运。
答案 1 :(得分:0)
不是在撤消后编写更新余额的代码,而是在帐户中编写更新触发器 - 这样可以更好地进行编程。
让我知道任何进一步的帮助