靠,自己搞出来了
create or replace trigger inupdetable
before update or delete or insert on table_a
for each row
declare
c number;
begin
--判断数据库内是否有数据
select count(*) into c from table_b where id = :new.id;
--没有数据的操作
if c = 0 then
--插入
if inserting then
insert into table_b(id,username,age,createtime,sate)
values
(:new.id,
:new.username,
:new.age,
sysdate,
'I');
--更新
elsif updating then
insert into table_b(id,username,age,updatetime,sate)
values
(:new.id,
:new.username,
:new.age,
sysdate,
'U');
--删除
elsif deleting then
update table_b
set username
= :old.username,
age
= :old.age,
deletetime
= sysdate,
sate
= 'D'
where id
= :old.id;
end if;
--有数据的操作
else
--插入
if inserting then
update table_b
set username
= :new.username,
age
= :new.age,
createtime
= sysdate,
sate
= 'I'
where id
= :new.id;
--删除
elsif deleting then
update table_b
set username
= :old.username,
age
= :old.age,
deletetime
= sysdate,
sate
= 'D'
where id
= :new.id;
--更新
elsif updating then
update table_b
set username
= :new.username,
age
= :new.age,
updatetime
= sysdate,
sate
= 'U'
where id
= :new.id;
end if;
end if;
end;