CREATE OR REPLACE FUNCTION HORAS_SOLICITACAO_PROJ
   (P_CDFILIAL      IN TAREFA.CDFILIAL%TYPE,
    P_NRSOLICITA    IN SOLISERV.NRSOLISERV%TYPE,
    P_GRUPOPROCESSO IN VARCHAR2) RETURN NUMBER
AS
   V_VRTEMPO      PLANATIVTARE.QTTEMPLAITAR%TYPE;
BEGIN
   SELECT NVL(SUM(PL.QTTEMPLAITAR),0)
     INTO V_VRTEMPO
     FROM TAREFA TF, PLANATIVTARE PL,
          (SELECT PG.CDGRUPROCESSO, PR.CDPROCESSO, PR.CDARVPROCESS, PR.NMPROCESSO
             FROM PROCESGPROC PG, PROCESSO PAUX, PROCESSO PR, PARAMGPROC PAR
            WHERE PAR.IDPARAMGPROC = P_GRUPOPROCESSO
              AND PR.CDARVPROCESS LIKE PAUX.CDARVPROCESS||'%'
              AND PG.CDPROCESSO = PAUX.CDPROCESSO
              AND PAR.CDGRUPROCESSO = PG.CDGRUPROCESSO) ATI
    WHERE (TF.CDFILIAL   = P_CDFILIAL)
      AND (TF.NRSOLISERV = P_NRSOLICITA)
      AND (TF.CDFILIAL   = PL.CDFILIAL)
      AND (TF.NRTAREFA   = PL.NRTAREFA)
      AND (PL.CDPROCESSO = ATI.CDPROCESSO);
   RETURN(V_VRTEMPO);
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('HORAS_SOLICITACAO','5.07.009'); END;
/
