CREATE OR REPLACE FUNCTION VALOR_PEDIDO_VRTOTAITEM(
   P_CDFILIAL     IN FILIAL.CDFILIAL%TYPE,
   P_NRPEDIDO     IN PEDIDO.NRPEDIDO%TYPE) RETURN NUMBER IS

   V_VRITEM NUMBER;
BEGIN
   V_VRITEM := 0;
   SELECT NVL(SUM((I.QTITEMPED * ROUND(I.VRPREUNITPED,2))),0) VRITEM
     INTO V_VRITEM
     FROM ITEMPEDIDO I
    WHERE I.CDFILIAL = P_CDFILIAL
      AND I.NRPEDIDO = P_NRPEDIDO;

   RETURN(V_VRITEM);
END;
/