Bonjour,
J'utilise Oracle 10g et je suis en train de faire une requête relativement compliquée mais je suis bloqué à un point. Je le résume ici. C'est un exemple débile au niveau du sens des requêtes imbriqués car on se répète mais qui illustre bien mon problème.
Rassurez vous, dans ma requête, je n'ai pas ce genre de répétition.

Pour une requête du type :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
 
SELECT age FROM (
         SELECT * FROM employes WHERE age > 25
)
WHERE
          age > (SELECT * FROM employes WHERE age > 25)
AND
          age > (SELECT * FROM employes WHERE age > 25)
Ma question est la suivante : Comment faire pour éviter d'effectuer à chaque fois cette sous-requête
Code : Sélectionner tout - Visualiser dans une fenêtre à part
SELECT * FROM employes WHERE age > 25
?

Pour les cheveronnés , voici ma requête :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
SELECT SUM(rec.LONGUEUR) FROM G_REC rec, (
SELECT ID_STRUCTURE FROM (
	SELECT rownum AS numero, structure.*, rang
	FROM g_structures structure
	START WITH structure.id_structure_pere = 0 CONNECT BY structure.id_structure_pere = PRIOR structure.id_structure ORDER SIBLINGS BY structure.rang
) resultats
WHERE numero >= 
	( SELECT numero2 FROM 
			(SELECT rownum AS numero2, structure.*, rang
			FROM g_structures structure
			START WITH structure.id_structure_pere = 0 CONNECT BY structure.id_structure_pere = PRIOR structure.id_structure ORDER SIBLINGS BY structure.rang)
	  WHERE ID_STRUCTURE = 159138)
AND numero <= 
	( SELECT numero2 FROM 
			(SELECT rownum AS numero2, structure.*, rang
			FROM g_structures structure
			START WITH structure.id_structure_pere = 0 CONNECT BY structure.id_structure_pere = PRIOR structure.id_structure ORDER SIBLINGS BY structure.rang)
	  WHERE ID_STRUCTURE = 159140)) structures
WHERE rec.ID_STRUCTURE = structures.ID_STRUCTURE
On voit bien ici que l'on repête la requête
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
 
SELECT rownum AS numero2, structure.*, rang
FROM g_structures structure
START WITH structure.id_structure_pere = 0 CONNECT BY structure.id_structure_pere = PRIOR structure.id_structure ORDER SIBLINGS BY structure.rang
3 fois et vu que c'est un traitement pour un arbre, c'est plutôt long d'où ma question.

Merci d'avance !