嗨,这是我的第一篇文章,很抱歉,如果之前有人询问的话。我正在尝试创建一个程序,它将增加存款账户(对于特定银行)的兴趣,并在屏幕上输出客户名称和存款账户的新余额。但是,我似乎无法让它工作。
CREATE OR REPLACE PROCEDURE addInterestNew(bank VARCHAR, interestRate INT out) AS
CURSOR CustomerBalance IS
SELECT customerName, balance
FROM Deposit
WHERE branchName = bank;
aCustomerName Deposit.customerName%TYPE;
newBalance Deposit.balance%TYPE
BEGIN
UPDATE DEPOSIT
SET balance = balance * (1 + (interestRate/100))
WHERE branchName = bank;
FETCH
OPEN CustomerBalance;
LOOP
FETCH CustomerBalance into aCustomerName,newbalance;
EXIT WHEN CustomerBalance%notfound;
dbms_output.put_line('CustomerName='||aCustomerName ||'balance='||newBalance);
END LOOP;
CLOSE CustomerBalance;
END;
/
任何帮助都是值得赞赏的
感谢
答案 0 :(得分:0)
似乎大多数代码都没问题,你只需要在光标打开之前有一个额外的FETCH
,应删除它。此外,在newBalance
变量声明后,您缺少分号。除此之外,您将interestRate
参数声明为IN OUT
,但您似乎无法在任何地方对其进行修改。不过,这应该有效:
CREATE OR REPLACE PROCEDURE addInterestNew(bank VARCHAR, interestRate INT out) AS
CURSOR CustomerBalance IS
SELECT customerName, balance
FROM Deposit
WHERE branchName = bank;
aCustomerName Deposit.customerName%TYPE;
newBalance Deposit.balance%TYPE;
BEGIN
UPDATE DEPOSIT
SET balance = balance * (1 + (interestRate/100))
WHERE branchName = bank;
OPEN CustomerBalance;
LOOP
FETCH CustomerBalance into aCustomerName,newbalance;
EXIT WHEN CustomerBalance%notfound;
dbms_output.put_line('CustomerName='||aCustomerName ||'balance='||newBalance);
END LOOP;
CLOSE CustomerBalance;
END;
/