This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH RECURSIVE cte_recursiva (entid,entnome,orgentidpai,seq,path, catid, orgstatus ) | |
AS | |
( | |
SELECT org.entid, ent.entnome, org.orgentidpai, 0 seq, CAST (org.entid AS varchar) as path, cat.catid, org.orgstatus | |
FROM entidade.organograma as org | |
INNER JOIN entidade.entidade as ent on ent.entid = org.entid | |
LEFT JOIN entidade.categoriaorganograma AS cat ON cat.catid = org.catid | |
WHERE org.orgentidpai = 756433 -- Filho da auditoria Interna | |
UNION ALL | |
SELECT g.entid,e.entnome, g.orgentidpai, seq+1, path || '>' || g.entid, cat.catid, g.orgstatus |