ALTER FUNCTION "DBA"."existid_ravolist"( in a_klass char(16), in a_nimi char(100) default 'Uus rahavoog' ) 
returns integer
begin
  declare ll_ravonr integer;
  set a_klass = "left"(a_klass+space(16),16);
  select first ravolist.ravonr into ll_ravonr from ravolist where ravolist.ravo = a_klass order by ravolist.kell desc;
  if ll_ravonr = 0 or ll_ravonr is null then
    insert into ravolist( ravo,nimi ) values( a_klass, a_nimi ) ;
    select ravolist.ravonr into ll_ravonr from ravolist where ravolist.ravo = a_klass
  end if;
  return(ll_ravonr)
end