I am trying to create a trigger that updates another table with PL/SQL and I am having some problems. (I have read this but doesn't help a lot).
Here is my situation, I have lets say 2 tables :
Customers Table
CustomerID number Primary Key, ItemsDelivered number
Items Table
CustomerID number, ItemID number, ItemDelivered Varchar(15)
Lets say that when somenone places an order we have a new record at Items table that looks like this:
| CustomerID | ItemID | ItemDelivered |
| 1 | 1 | False |
I want a trigger that will raise the ItemsDelivered counter whenever someone updates the ItemDelivered collumn to "True".
create or replace Trigger UpdateDelivered
After Update On Items For
Each Row
Declare
Counter Customers.ItemsDelivered%Type;
Begin
If (:Old.ItemDelivered ='False' And :New.ItemDelivered='True') Then
Select ItemsDelivered into Counter From Customers where CustomerdID =:New.CustomerID;
Update....
end if;
END;
Here is my problem, if only the ItemDelivered column is updated there is no New.CustomerID!
Is there any way to get the CustomerID of the row that have just updated? (I have tried to join with inserted virtual table but I am getting an error that the table doesn't exists)