需求:新建一个触发器,在数据表插入或者更新数据时自动获取当前系统时间作为update_time。
create or replace trigger trg_GEC_CManager before insert or update on GEC_CManager
for each row
begin
if inserting then
select GEC_CManager_seq.nextval into :new.id from dual;
else
:new.updateTime := sysdate;
end if;
end;
其中trg_GEC_CManager 是触发器名,在同一个数据库中是唯一的,GEC_CManager是当前表名,当对GEC_CManager表执行插入和更新操作时,字段update_time就会获取当前系统时间作为内容,而不用人工为该字段赋值。这就是一个最简单,最常用的触发器例子。