CREATE OR REPLACE 
TRIGGER ATUALIZA_ITEMTRABALHO
BEFORE INSERT OR UPDATE OF CDPROGSIST ON SOLISERV FOR EACH ROW
DECLARE
   V_ITEM VARCHAR(10);
BEGIN
   IF :OLD.CDPROGSIST||'-' <> :NEW.CDPROGSIST||'-' THEN
      IF :NEW.CDPROGSIST IS NOT NULL THEN
         SELECT MIN(CDITEMTRAB) INTO V_ITEM
           FROM ITEMTRAB
          WHERE CDARVITTRAB LIKE '%'||:NEW.CDPROGSIST||'%';
      END IF;
      :NEW.CDITEMTRAB := V_ITEM;
   END IF;
END;
/