1

嗨,这是我的第一篇文章,如果之前有人问过,很抱歉。我正在尝试创建一个程序,该程序将为存款账户(针对特定银行)增加利息,并将客户姓名和存款账户的新余额输出到屏幕上。但我似乎无法让它工作。

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;
/

任何帮助表示赞赏

谢谢

4

1 回答 1

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;
/
于 2013-11-14T21:36:42.050 回答