ALTER FUNCTION "DBA"."existid_sublist"( in a_klass char(16), in a_nimi char(100) default 'Uus subjekt' ) 
returns integer
begin
  declare ll_subjectnr integer;
  set a_klass = "left"(a_klass+space(16),16);
  select first sublist.subjectnr into ll_subjectnr from sublist where sublist.subject = a_klass order by sublist.kell desc;
  if ll_subjectnr = 0 or ll_subjectnr is null then
    insert into sublist( subject,nimi ) values( a_klass, a_nimi ) ;
    select sublist.subjectnr into ll_subjectnr from sublist where sublist.subject = a_klass
  end if;
  return(ll_subjectnr)
end