表1:客户
cust_no | cust_credbal | 信用状态
表2:customer_credittopup
cust_no | 交易金额
我有上面两个表,我在插入到更新后写了一个更新Table2
触发器Table1
。因此,Table1
cust_credbal
在添加cust_credbal
in Tabl1
+ in 中的新值后, trans_amount
in的金额会更新Table2
。如何在更新后添加 if 语句以检查是否cust_credbal
大于 20 则cred_status
设置为“有效”否则“已耗尽”
我的触发器显示此错误:第 8 行错误:PLS-00049:错误绑定变量 'NEW.CUST_CREDITBAL'
CREATE OR REPLACE TRIGGER after_insert_credittopup
AFTER INSERT ON customer_credittopup
FOR EACH ROW
DECLARE
credit number(11);
BEGIN
UPDATE customers
SET cust_creditbal=cust_creditbal +:new.trans_amount
WHERE cust_no=:new.cust_no;
SELECT Cust_creditbal INTO credit
FROM customers WHERE cust_no=:new.cust_no;
IF(:new.cust_creditbal>0) THEN
UPDATE customers
SET Cust_credstatus='Valid'
WHERE cust_no=:new.cust_no;
end if;
end;
/