【发布时间】:2015-04-30 21:49:51
【问题描述】:
我正在尝试制作一个简单的触发器,在付款时更新客户余额。错误显示在 begin 语句之后。我试图在 where 语句中使用新插入的 customerID 并再次向下几行来计算新的余额。有人可以帮助我正确的语法吗?表格位于底部。
--Whenever a payment is made, customer amount owed is adjusted
create or replace trigger paymentUpdate
after insert on payment
for each row
when (new.transactionID > 0)
declare
newAmount decimal(7,2);
currentBalance decimal(7,2);
begin
--Get the outstanding customer balance
select amountOwed into currentBalance
from customer
where customer.customerID=:new.customerID; --Does this do what I think it does?
-- ^^is any of this needed?
--Subtracts the recently made payment from the customer balance
newAmount := currentBalance - :new.amount;
--Update customer amount owed
update customer.amountOwed
set amountOwed = newAmount
where customer.customerID=:new.customerID;
dbms_output.put_line('Original account balance was: '||currentBalance);
dbms_output.put_line('Payment made was: $'||:new.amount); --Check this
dbms_output.put_line('Customer account balance is now: '||newAmount);
end paymentUpdate;
/
--commit needed?
表格:
INSERT INTO customer (customerID, name, address, insurance, contactInfo, customerType, licenseNumber, amountOwed)
VALUES (45124512, 'Bob Jones', '232 Sycamore Ln.', 'Pekin', 3095555145, 'New', 'SSSSFFFYYDDD', 220.00);
INSERT INTO customer (customerID, name, address, insurance, contactinfo, customertype, licensenumber, amountOwed)
VALUES (12892222, 'Mike Tyson','100 Haters Rd.', 'Progressive', 2175555555, 'Regular', 'FGHJHHHHTYYY', 42.00);
INSERT INTO payment (customerID, transactionID, amount, method, payDate)
VALUES (45124512, 56785678, 220.00, 'Credit Card', '25-JUN-15');
INSERT INTO payment (customerID, transactionID, amount, method, payDate)
VALUES (12892222, 68689000, 42.00, 'Cash', '25-JUN-15');
错误: 7/1 PL/SQL:忽略 SQL 语句 9/6 PL/SQL: ORA-00942 表或视图不存在 16/1 PL/SQL:SQL 语句被忽略 16/17 PL/SQL: ORA-00942 表或视图不存在
【问题讨论】:
-
请编辑您的问题并包含您看到的错误。谢谢。