TRIGGER "TR_JBPM4_HIST_TASK_I" 
   before insert on JBPM4_HIST_TASK
   referencing new as new old as old
   for each ROW
declare 
  syptaskid number(19,0);
	t_count number(2);
begin
  IF inserting THEN
	select count(*) INTO t_count from dual where exists(select 1 from JBPM4_TASK t where t.DBID_=:new.dbid_);
	IF (t_count > 0) then
		select t.SUPERTASK_ into syptaskid from JBPM4_TASK  t WHERE t.DBID_ =:new.dbid_ ;
	  	:new.SUPERTASK_:=syptaskid;
	END IF;
  END IF;
end TR_JBPM4_HIST_TASK_I;


TRIGGER "TR_JBPM4_TASK_UD"
   before update or delete on JBPM4_TASK
   for each ROW
begin
  IF updating THEN
	 UPDATE JBPM4_HIST_TASK SET SUPERTASK_ =:NEW.SUPERTASK_ WHERE DBID_=:NEW.dbid_;
  ELSE
     UPDATE JBPM4_HIST_TASK SET SUPERTASK_ =:OLD.SUPERTASK_ WHERE DBID_=:OLD.dbid_;
  END IF;
end TR_JBPM4_TASK_UD;
