【问题标题】:How to create date trigger?如何创建日期触发器?
【发布时间】:2021-06-28 02:54:50
【问题描述】:

如何创建触发器以将表中的日期数据与下一行一起增加?我试过了,在桌子下面

我想要做的是将日期从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;

【问题讨论】:

    标签: sql oracle triggers


    【解决方案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;
    

    因为,您的触发器将遭受 mutating table 错误(如果您插入多行),并且 - 在这种情况下不会执行任何操作(因为您想要更新还不存在)。

    【讨论】:

      猜你喜欢
      • 2013-04-05
      • 1970-01-01
      • 1970-01-01
      • 2020-10-22
      • 2010-10-08
      • 1970-01-01
      • 1970-01-01
      • 2014-12-04
      • 2011-10-14
      相关资源
      最近更新 更多