ALTER FUNCTION "DBA"."existid_meetlist"(in a_klass char(16), in a_nimi char(100) default 'Uus meede')
returns integer
begin
  declare ll_meetnr integer;
  set a_klass="left"(a_klass+space(16),16);
  select first meetlist.meetnr into ll_meetnr from meetlist where meetlist.meet = a_klass order by meetlist.kell desc;
  if ll_meetnr = 0 or ll_meetnr is null then
    insert into meetlist( meet,nimi) values( a_klass, a_nimi) ;
    select meetlist.meetnr into ll_meetnr from meetlist where meetlist.meet = a_klass
  end if;
  return(ll_meetnr)
end