Oracle 11g Query ( Funcionando como esperado! )
WITH ADRECURSIVEUSERLEADER (CDLEADER,CDUSER,NMUSER,FGUSERENABLED)
AS
(
SELECT US.CDLEADER AS CDLEADER
,US.CDUSER AS CDUSER
,US.NMUSER
,US.FGUSERENABLED
FROM ADUSER US
WHERE 1 = 1
UNION ALL
SELECT RS.CDLEADER
,US.CDUSER
,US.NMUSER
,US.FGUSERENABLED
FROM ADRECURSIVEUSERLEADER RS
INNER JOIN ADUSER US
ON RS.CDUSER = US.CDLEADER
WHERE 1 = 1
)
SELECT *
FROM ADRECURSIVEUSERLEADER T
WHERE 1 = 1;
Oracle 10g Query ( Como estamos tentando fazer )
WITH ADRECURSIVEUSERLEADER
AS
(
SELECT US.CDLEADER AS CDLEADER
,US.CDUSER AS CDUSER
,US.NMUSER
,US.FGUSERENABLED
FROM ADUSER US
START WITH US.CDLEADER IS NULL -- parent
CONNECT BY PRIOR US.CDUSER = US.CDLEADER -- child / parent
)
SELECT *
FROM ADRECURSIVEUSERLEADER T
WHERE 1 = 1;
Qual é o problema?
Nós temos a seguinte estrutura de liderança:
User code (CDUSER) 5 is the CEO
User code (CDUSER) 21 is the Manager (Leaded by 5)
User code (CDUSER) 937 is the Leader (Leaded by 21)
User code (CDUSER) 1276 is the Developer (Leaded by 937)
Se eu pesquisar pelo Líder no 10g e 11g :
AND T.CDLEADER = 21
* Um para o 937 ( Leader )
* Um para o 1276 ( Developer )
10g me trás apenas um registro:
* Um para o 937 ( Leader )
--------------------------------------
SQL Fiddle Example : http://sqlfiddle.com/#!4/8200a/1/0
DDL for Oracle:
CREATE TABLE ADUSER (CDUSER NUMBER(10)
,CDLEADER NUMBER(10)
,FGUSERENABLED NUMBER(2)
,NMUSER VARCHAR2(255) );
INSERT INTO ADUSER VALUES ( 5, NULL, 1, 'CEO Name');
INSERT INTO ADUSER VALUES ( 21, 5, 1, 'Manager Name');
INSERT INTO ADUSER VALUES ( 937, 21, 1, 'Leader Name');
INSERT INTO ADUSER VALUES (1276, 937, 1, 'Developer Name');
O que precisamos?
Nós precisamos saber todos que estão abaixo do líder pesquisado ( Inclusive liderados do liderado pelo líder e assim por diantfazer isso no Oracle 10gsso no Oracle 10g?
Muito Obrigado!