开发者

Oracle SQL trigger for automatically set a column value

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

The trigger I wrote is:

create or replace trigger MyProduct_id_trg 
after insert on MyProduct
begin 
   update MyProduct set productId = inserted.oid where oid = inserted.oid;
end; 
开发者_如何学C

However, this does not work.

Can someone help me with this?

Regards.


Looks like you are trying to use SQL Server syntax on an Oracle database! Try this:

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.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜