CREATE FUNCTION "dba"."pa_resdef_rida"( in a_resdefnr integer, in a_perlop date default Now() )
RETURNS decimal(15,3)
BEGIN
  declare ldc_pvi decimal(15,3);
  call pa_resdef(a_resdefnr, a_perlop);
  select Sum("gl_pl_resdef"."arvestatud"-"gl_pl_resdef"."saadud"-"gl_pl_resdef"."aegunud") into ldc_pvi from gl_pl_resdef;
  return ldc_pvi;
END