ALTER FUNCTION "DBA"."existid_artlist"( in a_klass char(16), in a_nimi char(100) default 'Uus kulu liik' ) 
returns integer
begin
  declare ll_artnr integer;
  set a_klass = "left"(a_klass+space(16),16);
  select first artlist.artnr into ll_artnr from artlist where artlist.art = a_klass order by artlist.kell desc;
  if ll_artnr = 0 or ll_artnr is null then
    insert into artlist( art,nimi ) values( a_klass, a_nimi ) ;
    select artlist.artnr into ll_artnr from artlist where artlist.art = a_klass
  end if;
  return(ll_artnr)
end