Table1: customers
cust_no | cust_credbal | cred_status
Table2:customer_credittopup
cust_no | trans_amount
I have the above two tables, I have written an update trigger after insert into the Table2 to update Table1. Thus the amount in Table1 cust_credbal is updated after adding cust_credbal in Tabl1 + the new value in trans_amount in Table2. How do i add an if statement after the update to check if cust_credbal is > than 20 then cred_status is is set to 'VALID' else 'EXHAUSTED'
My trigger showing this error: Error at line 8: PLS-00049: bad bind variable '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;
/
customers,:new.cust_creditbalwould make sense only inside the trigger oncustomerstable.