Bonjour,

Nous avons mis les éléments suivants dans la table ARBRE :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
INSERT INTO ARBRE (pere, fils) VALUES ('A','A');
INSERT INTO ARBRE (pere, fils) VALUES ('A','B');
INSERT INTO ARBRE (pere, fils) VALUES ('B','D');
INSERT INTO ARBRE (pere, fils) VALUES ('D','H');
INSERT INTO ARBRE (pere, fils) VALUES ('D','I');
INSERT INTO ARBRE (pere, fils) VALUES ('B','E');
INSERT INTO ARBRE (pere, fils) VALUES ('A','C');
INSERT INTO ARBRE (pere, fils) VALUES ('C','F');
INSERT INTO ARBRE (pere, fils) VALUES ('C','G');

Nous souhaitons à partir d’une requête hiérarchique obtenir pour chaque nœuds la distance de tous ses ascendants directs.

Description de l’arbre :
A
..+__ B
........+__ D
..............+__ H
..............+__ I
........+__ E
..+__ C
........+__ F
........+__ G


Résultat à obtenir :

Parent | fils | distance
null | A | 0
A | B | 1
B | D | 1
D | H | 1
D | I | 1
B | E | 1
A | C | 1
C | F | 1
C | G | 1
A | D | 2
B | H | 2
B | I | 2
A | E | 2
A | F | 2
A | G | 2
A | H | 3
A | I | 3

Merci pour votre aide.