create or replace trigger tg_java5_backup after --执行sql之后执行--before是事前触发器,after是事后触发器 insert or update or delete --增、删、改都触发 on java5 for each row--行级触发器 declare begin if inserting then insert into java5_back(id,name,gz)values(:new.id,:new.name,:new.gz); elsif updating then update java5_back set id=:new.id,name=:new.name,gz=:new.gz; elsif deleting then delete from java5_back where id=old.id; end if; exception when others then raise_application_error(-20003, '备份失败'); end;
时间: 2024-04-10 07:27:09 浏览: 135
CREATE-OR-REPLACE-TRIGGER.rar_SQL trigger_trigger
这是一个用于在执行SQL操作后触发的触发器。它可以在插入、更新或删除数据时备份相关数据到另一个表中。具体的代码如下:
```sql
create or replace trigger tg_java5_backup
after insert or update or delete on java5
for each row
declare
begin
if inserting then
insert into java5_back(id, name, gz) values (:new.id, :new.name, :new.gz);
elsif updating then
update java5_back set id = :new.id, name = :new.name, gz = :new.gz;
elsif deleting then
delete from java5_back where id = :old.id;
end if;
exception
when others then
raise_application_error(-20003, '备份失败');
end;
```
这个触发器会在java5表的每一行数据被插入、更新或删除后执行相应的备份操作。如果备份过程中出现异常,会抛出一个应用错误。
阅读全文