用于自动设置列值的 Oracle SQL 触发器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6733148/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Oracle SQL trigger for automatically set a column value
提问by Kevin
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.
我正在编写一个 Oracle 触发器。此触发器应自动将“productId”列的值设置为刚刚插入的行的 oid。
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;
However, this does not work.
但是,这不起作用。
Can someone help me with this?
有人可以帮我弄这个吗?
Regards.
问候。
回答by Tony Andrews
Looks like you are trying to use SQL Server syntax on an Oracle database! Try this:
看起来您正在尝试在 Oracle 数据库上使用 SQL Server 语法!尝试这个:
create or replace trigger MyProduct_id_trg
before insert on MyProduct
for each row
begin
:new.productId := :new.oid;
end;
(Note: beforenot after, and with for each row
.)
(注意:之前不是之后,和for each row
。)