oracle触发器添加更新删除数据到相同结构临时表

create or replace trigger ToTemp after insert or update or delete
on info for each row
declare//声明变量
    integrity_error exception;
    errno            integer;

    errmsg           char(200);

    sexy     varchar2(20); 


begin
if inserting then
    select sex into sexy from info;
    insert into info_temp(ID,UserName,Sex,Status) values(:NEW.ID,:NEW.UserName,sexy);//:NEW.UserName的值为表info新增加的数据
elsif updating then
    update info_temp set ID=:NEW.ID,UserName=:NEW.UserName where id=:OLD.id;
elsif deleting then
    delete from info_temp where id=:OLD.id;
end if;
exception
    when integrity_error then
       raise_application_error(errno, errmsg);
end;

你可能感兴趣的:(oracle触发器添加更新删除数据到相同结构临时表)