表1:客户
cust_no | cust_credbal | cred_status
表2:customer_credittopup
cust_no | trans_amount
我有上面的两个表,在插入Table2
以更新Table1
之后,我写了一个更新触发器。因此,在Table1
中添加cust_credbal
+ cust_credbal
中的Tabl1
中的新值后,trans_amount
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;
/
答案 0 :(得分:2)
这里似乎只需要1个更新声明:
UPDATE customers
SET cust_creditbal=cust_creditbal +:new.trans_amount,
Cust_credstatus = CASE WHEN cust_creditbal +:new.trans_amount > 0 THEN 'Valid'
ELSE 'Invalid'
--or if you don't want to change status in such case just put
--ELSE Cust_credstatus
END
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;
答案 1 :(得分:0)
NEW.CUST_CREDITBAL
与cust_credbal