CREATE OR REPLACE FUNCTION VERSAOORCA_GOP
   (P_NRHISTORCAMENTOGOP IN NUMBER,
    P_IDTIPOORCAOP IN NUMBER) RETURN NUMBER IS

 V_RESULT NUMBER;

BEGIN
   SELECT NVL(MAX(NRVERSAO),0)
     INTO V_RESULT
     FROM HISTITEMORCAGOP
    WHERE NRHISTORCAMENTOGOP = P_NRHISTORCAMENTOGOP
      AND IDTIPOORCAOP = P_IDTIPOORCAOP;

   RETURN(V_RESULT);
END;
/
