oracle 中两张表同步的触发器

    技术2022-05-19  25

    /*创建表A*/create table A_ybl (

       y                   INTEGER                         not null,

       b            VARCHAR(30)                     not null,

       l            VARCHAR(20)                     not null  

    );/*创建表A的备份表*/

    create table A_ybl2 (

       y                   INTEGER                         not null,

       b            VARCHAR(30)                     not null,

       l            VARCHAR(20)                     not null  

    );create or replace trigger test after insert or update or delete on  A_ybl for each row

    declare error_exception exception,errno integer,errmsg  char(20),dummy integer,found boolean;

    begin if inserting  then     insert into  A_ybl2 values(:NEW.y,:NEW.B,:NEW.l); elsif updating then         update A_ybl2 set y=:NEW.y,                   b=:NEW.b,                   l=:NEW.l               where id:=:OLD.y;      elsif deleting  then           delete from A_ybl2  where y=:old.id; end if;  exception  when error_exception   then  raise_application_error(errno,errmsg); end;                                                

     

     


    最新回复(0)