ALTER FUNCTION "dba"."get_dk_kontod_spank"(in id_skoop integer,in a_spank smallint default 2,in id_obj integer default 0,in a_mke smallint default 2,in a_viivis smallint default 2)
returns char(7000)
begin
  declare ls_dk_kontod char(7000);
  declare ls_djkonto char(7);
  declare err_notfound exception for sqlstate value '02000';
  declare c_dk_obj dynamic scroll cursor for select if dk_obj.djkonto is null then 'x1y2z3' else dk_obj.djkonto endif
    from dk_obj
    where (dk_obj.skoop=id_skoop or id_skoop=0) and
          (dk_obj.spank=a_spank or a_spank=2) and
          (dk_obj.objnr=id_obj or id_obj=0) and
          (dk_obj.mke=a_mke or a_mke=2) and
          (dk_obj.viivis=a_viivis or a_viivis=2);
  set ls_dk_kontod=';';
  open c_dk_obj;
  dk_obj_loop: loop
    fetch next c_dk_obj into ls_djkonto;
    if sqlstate = err_notfound then
      leave dk_obj_loop
    end if;
    set ls_dk_kontod=ls_dk_kontod+"Left"(ls_djkonto+Space(7),7)+';'
  end loop dk_obj_loop;
  close c_dk_obj;
  return(ls_dk_kontod)
end