create or replace function f_get_osia_plpd(plpdId number, inventoryDate date)
  return number is
  res             number;
  v_plpdId        number := plpdId;
  v_inventoryDate date := inventoryDate;
begin
  select SUM(ONSI.QUANTITY) into res
          from ONSITEINVENTORYADJUSTMENT ONSI
         where ONSI.PRODUCTLISTPERDISTRIBPOINT_ID = v_plpdId
          and ONSI.INVENTORYDATE <= v_inventoryDate;
  return res;
end f_get_osia_plpd;
/
