Oracle SQL trigger to automatically set a column value

I am writing an Oracle trigger. This trigger should automatically set the value of the "productId" column to the value of the row just inserted.

I wrote a trigger:

create or replace trigger MyProduct_id_trg after insert on MyProduct begin update MyProduct set productId = inserted.oid where oid = inserted.oid; end; 

However, this does not work.

Can someone help me?

Sincerely.

+4
source share
1 answer

It looks like you are trying to use SQL Server syntax in an Oracle database! Try the following:

 create or replace trigger MyProduct_id_trg before insert on MyProduct for each row begin :new.productId := :new.oid; end; 

(Note: before not after, and with for each row .)

+11
source

All Articles