bhr
bhr

Reputation: 555

Update column in another table with trigger

I would like to update a column in another table with the code below but I get a error that the trigger is invalid. Whats wrong with it?

CREATE OR REPLACE TRIGGER UPDATE_PAYMENT
  AFTER INSERT OR UPDATE ON PAYMENT
  for each row

begin
  update PAYMENTTYPE PT
  set PT.PAYMENTTYPECOLUMN = PAYMENT.PAYMENTTYPECOLUMN
  where PT.ID = :NEW.ID and PT.ID2 = :NEW.ID2;

end UPDATE_PAYMENT;

Upvotes: 1

Views: 55

Answers (1)

Aleksej
Aleksej

Reputation: 22949

In your trigger you refer twice to PAYMENT columns by :NEW., and this is correct, while the third time you use PAYMENT., which is wrong. The trigger should be:

CREATE OR REPLACE TRIGGER UPDATE_PAYMENT
  AFTER INSERT OR UPDATE ON PAYMENT
  for each row
begin
  update PAYMENTTYPE PT
  set PT.PAYMENTTYPECOLUMN = :NEW.PAYMENTTYPECOLUMN   -- <------ HERE
  where PT.ID = :NEW.ID and PT.ID2 = :NEW.ID2;
end UPDATE_PAYMENT;

Upvotes: 2

Related Questions