create or replace trigger denik_log
before update or insert or delete
on denik for each row
declare
  kod      integer;
  id_co    integer;
begin
if :old.radekd is NULL and :new.radekd is NOT NULL then		--insert
  kod:=:new.kod;
  id_co:=:new.radekd;
  insert into log(id,kdy,kod,jak,radek) 
         values(seq_log.nextval,sysdate,kod,'INSERT',id_co);
end if;
if :old.radekd is NOT NULL and :new.radekd is NOT NULL then		--update
  kod:=:new.kod;
  id_co:=:new.radekd;
  insert into log(id,kdy,kod,jak,radek) 
         values(seq_log.nextval,sysdate,kod,'UPDATE',id_co);
end if;
if :old.radekd is not NULL and :new.radekd is NULL then	        	--delete
  kod:=:old.kod;
  id_co:=:old.radekd;
  insert into log(id,kdy,kod,jak,radek) 
         values(seq_log.nextval,sysdate,kod,'DELETE',id_co);
end if;
end;
/
