DECLARE 
 cursor  c_toma is
 select * from inv_detexisfis
 where secuencia=2
 and costo=0
 for update of costo;
 vcosto number;
begin
  for a in c_toma
  loop
   begin
      select COSTO into vcosto
      from fac_det_precios
      where cod_cia='001'
      and cod_lista_precio='001'
      and cod_articulo = a.cod_articulo;
      if vcosto is not null then
         update inv_detexisfis
         set costo=vcosto
         where current of c_toma;
      end if;
    exception 
     when no_data_found then
        null;
   end;
  end loop;
end;

-- Costeo a partir de las Compras
DECLARE 
 cursor  c_toma is
 select * from inv_detexisfis
 where secuencia=2
 and costo=0
 for update of costo;
 vcosto number;
begin
  for a in c_toma
  loop
   begin
      select max(PRECIO_UNITARIO_FOB)
      into vcosto
      from com_det_factura
      where cod_cia ='001'
      and cod_bodega='001'
      and cod_articulo = a.cod_articulo;
      if vcosto is not null then
         update inv_detexisfis
         set costo=vcosto
         where current of c_toma;
      end if;
    exception 
     when no_data_found then
        null;
   end;
  end loop;
end;
/