如何创建触发器来增加表中每一行的日期数据?我试过了,在桌子下面
我想要做的是将日期从 training_date_end
增加 1 周。但我不知道怎么做,只是学习。有人可以帮忙吗?
CREATE TABLE training
(
coach_id int NOT NULL,
customer_id int NOT NULL,
training_date_start date NULL,
training_date_end date NULL,
training_place_id int NOT NULL,
CONSTRAINT training_pk PRIMARY KEY (training_place_id)
);
create or replace trigger lucky_week
before insert or update on training
for each row
begin
update training
set training_date_end = :new.training_date_end + 7
where training_date_end = :new.training_date_end;
end;
答案 0 :(得分:1)
最有可能是这样的:
create or replace trigger lucky_week
before insert or update on training
for each row
begin
:new.training_date_end := :new.training_date_end + 7;
end;
因为,您的触发器将遭受变异表错误(如果您插入多行),并且 - 在这种情况下不会做任何事情(因为您想要的行更新尚不存在)。