Oracle里面怎样建立一个自动插入系统当前时间的触发器?表里面有一个更新时间字段。我想当我对表修改是,就自动为该字段插入系统当前时间 ,请问这个触发器该怎么写?

解决方案 »

  1.   

    create or replace trigger "tib_sys_function" before insert
    on SCOTT.SYS_FUNCTION for each row
    declare
        integrity_error  exception;
        errno            integer;
        errmsg           char(200);
        dummy            integer;
        found            boolean;begin
        --  Column "ID" uses sequence SCOTT.S_SYS_FUNCTION
        select SCOTT.S_SYS_FUNCTION.NEXTVAL INTO :new.ID from dual;--  Errors handling
    exception
        when integrity_error then
           raise_application_error(errno, errmsg);
    end;这个只是insert的,你再加个update,这里是 select SCOTT.S_SYS_FUNCTION.NEXTVAL INTO :new.ID from dual;
    你就改一下
     select 系统时间 INTO :new.时间字段 from dual;
      

  2.   

    update Table t
    set t.** = sysdate
    where t,id= ?;
    其他的上面的都写了最好加上一个 传入参数标记你这次更新的数据的 主键值 
    然后用给你的update语句直接把 语句补全了就ok