ALTER FUNCTION "DBA"."existid_taotlist"(in a_klass char(16), in a_nimi char(100) default 'Uus taotlus')
returns integer
begin
  declare ll_taotnr integer;
  set a_klass="left"(a_klass+space(16),16);
  select first taotlist.taotnr into ll_taotnr from taotlist where taotlist.taot = a_klass order by taotlist.kell desc;
  if ll_taotnr = 0 or ll_taotnr is null then
    insert into taotlist( taot,nimi) values( a_klass, a_nimi) ;
    select taotlist.taotnr into ll_taotnr from taotlist where taotlist.taot = a_klass
  end if;
  return(ll_taotnr)
end