日期:2014-05-16  浏览次数:20509 次

oracle 触发器编写
    //触发器名UserToTemp 
    create or replace trigger UserToTemp after insert or update or delete 
    on user_info for each row//对表user_info操作时触发以下事件 
    declare//声明变量 
        integrity_error exception; 
        errno            integer; 
        errmsg           char(200); 
        dummy            integer; 
        found            boolean; 
        sexy              varchar2(20); 
     
    begin 
    if inserting then 
        select sex into sexy from user_info_test;//取出user_info_test表中的sex字段的值赋值给变量sexy 
        insert into User_info_temp(ID,UserName,PassWord,Createdate,Status) values(:NEW.ID,:NEW.UserName,sexy,:NEW.createdate,:NEW.status);//:NEW.UserName的值为表user_info新增加的数据 
    elsif updating then 
        update User_info_temp set ID=:NEW.ID,UserName=:NEW.UserName,PassWord=:NEW.PassWord,Status=:NEW.Status where id=:OLD.id; 
    elsif deleting then 
        delete from User_info_temp where id=:OLD.id; 
    end if; 
    exception 
        when integrity_error then 
           raise_application_error(errno, errmsg); 
    end;