Skip to content

Instantly share code, notes, and snippets.

@buzztaiki
Created February 25, 2012 17:40
Show Gist options
  • Select an option

  • Save buzztaiki/1909684 to your computer and use it in GitHub Desktop.

Select an option

Save buzztaiki/1909684 to your computer and use it in GitHub Desktop.
update derive when to update base.
create table base (
id number,
value varchar2(32),
primary key (id)
);
create table derive (
id number,
value varchar2(32), value2 varchar2(32),
primary key (id),
foreign key (id) references base(id) on delete cascade
);
create or replace package my as
procedure update_derive(baserec base%rowtype);
end;
/
create or replace package body my as
procedure update_derive(baserec base%rowtype) is
begin
update derive d set d.value = baserec.value where d.id = baserec.id;
end;
end;
/
create or replace trigger base_on_update
after update on base for each row
declare
baserec base%rowtype;
begin
baserec.id := :new.id;
baserec.value := :new.value;
my.update_derive(baserec);
end;
/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment