我需要有关在table1上创建触发器的帮助 这将从table1中将特定列插入table2。 我怎样才能做到这一点?我正在使用Oracle 11G XE。
这是我的代码:
create trigger AllowanceTrigger
on ex_bulacan
after insert
as
insert into allowance VALUES (PLANT_ORIGIN,SO_NO, SO_STATUS,SO_REMARKS,DRIVER_NAME)
select plant_origin, sales_order_no, status,remarks, driver_name
from ex_bulacan;
go ;
当我运行该命令时,我收到此错误
ORA-04071: missing BEFORE, AFTER or INSTEAD OF keyword
解释是:
ORA-04071。 00000 - “关键字之前,之后或之后丢失”
*原因:触发器语句缺少BEFORE / AFTER / INSTEAD OF子句 *动作:指定BEFORE,AFTER或INSTEAD OF。
答案 0 :(得分:1)
PL / SQL中没有“go”语句,并且您没有遵循触发器定义的正确语法(它是well documented)
试试这个:
create trigger AllowanceTrigger
after insert on ex_bulacan
begin
insert into allowance (PLANT_ORIGIN,SO_NO, SO_STATUS,SO_REMARKS,DRIVER_NAME)
select plant_origin, sales_order_no, status,remarks, driver_name
from ex_bulacan;
end;
我不确定它是否符合你的意图。它会针对每个插入语句触发一次,而不是针对每一行触发,并且它会将ex_bulacan中的所有行插入到allowance中,而不仅仅是您刚刚插入的行。也许你想要的实际上是:
create trigger AllowanceTrigger
after insert on ex_bulacan
for each row
begin
insert into allowance (PLANT_ORIGIN,SO_NO, SO_STATUS,SO_REMARKS,DRIVER_NAME)
values (:new.plant_origin, :new.sales_order_no, :new.status, :new.remarks,
:new.driver_name);
end;
答案 1 :(得分:0)
代码中存在语法错误。您必须按以下顺序指定触发器:
CREATE TRIGGER AllowanceTrigger
AFTER INSERT
ON ex_bulacan