create or replace function Proleg_seqnum(current_uuid varchar2)
return number is
preuuid varchar2(36);
begin
select PRV_LEG_ID into preuuid from TERMINAL_PRO_LEG_TS where PROCEDURE_LEG_UUID=current_uuid;
if preuuid is null then return 1;
else return Proleg_seqnum(preuuid)+1;
end if;
end;