Salut
Une solution...
La fonction
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| create or replace function frecursive(i int) returns setof record
as
$$
declare
tligne t%rowtype;
r int;
begin
select no_lot, remplace into tligne from t where no_lot=i;
r=tligne.remplace;
while exists (select no_lot from t where no_lot=r)
loop
select no_lot, remplace into tligne from t where no_lot=r;
r=tligne.remplace;
return next tligne;
end loop;
end;
$$
language plpgsql |
L'appel de la fonction
select no_lot from frecursive(7) as (no_lot int, remplace int)
@+
Partager