Upgrade to Pro — share decks privately, control downloads, hide ads and more …

10 Features do Oracle que voce não conhecia - CONNECT BY CLAUSE

10 Features do Oracle que voce não conhecia - CONNECT BY CLAUSE

(Palestra ministrada no TechDay da MDIAS em JAN-2019)

Todo banco de dados possui features na qual desconhecemos, o que acaba nos levando a soluções mais complicadas ou menos eficientes, com o Oracle não é diferente. Por esse motivo, pretendo apresentar de forma bastante didática uma série com 10 features do Oracle 11g que eu desconhecia e que tem facilitado bastante minha vida desde meados de 2016.

Como primeira feature, apresento o CONNECT BY CLAUSE, na qual nos permite escrever consultas hierárquicas de forma simples levando todo o processamento para dentro do banco de dados. Além disso, também apresento outras maneiras de tirar proveito desta feature no dia a dia.

Rafael Ponte

January 31, 2019
Tweet

More Decks by Rafael Ponte

Other Decks in Technology

Transcript

  1. Name Null? Type ---------- -------- ------------- ID NOT NULL NUMBER(38)

    NOME NOT NULL VARCHAR2(200) CARGO NOT NULL VARCHAR2(100) GERENTE_ID NUMBER(38) describe tb_funcionarios;
  2. Name Null? Type ---------- -------- ------------- ID NOT NULL NUMBER(38)

    NOME NOT NULL VARCHAR2(200) CARGO NOT NULL VARCHAR2(100) GERENTE_ID NUMBER(38) describe tb_funcionarios;
  3. Name Null? Type ---------- -------- ------------- ID NOT NULL NUMBER(38)

    NOME NOT NULL VARCHAR2(200) CARGO NOT NULL VARCHAR2(100) GERENTE_ID NUMBER(38) describe tb_funcionarios; (FOREIGN KEY)
  4. Name Null? Type ---------- -------- ------------- ID NOT NULL NUMBER(38)

    NOME NOT NULL VARCHAR2(200) CARGO NOT NULL VARCHAR2(100) GERENTE_ID NUMBER(38) describe tb_funcionarios; (FOREIGN KEY)
  5. Chris Rafael Plauto Ricardo Stevens Thaio Principe Guto … Victor

    Aldeir Maia Pimentel Roberto … Hierarquia
  6. select f1.nome as funcionario ,f2.nome as gerente from tb_funcionarios f1

    ,tb_funcionarios f2 where f1.gerente_id = f2.id order by f.nome ;
  7. select f1.nome as funcionario ,f2.nome as gerente from tb_funcionarios f1

    ,tb_funcionarios f2 where f1.gerente_id = f2.id order by f.nome ;
  8. select f1.nome as funcionario ,f2.nome as gerente ,f3.nome as gerente_do_gerente

    from tb_funcionarios f1 ,tb_funcionarios f2 ,tb_funcionarios f3 where f1.gerente_id = f2.id and f2.gerente_id = f3.id order by f.nome ;
  9. select f1.nome as funcionario ,f2.nome as gerente ,f3.nome as gerente_do_gerente

    from tb_funcionarios f1 ,tb_funcionarios f2 ,tb_funcionarios f3 where f1.gerente_id = f2.id and f2.gerente_id = f3.id order by f.nome ;
  10. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id ;
  11. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id ;
  12. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id ;
  13. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id ;
  14. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id ;
  15. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id ;
  16. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id ;
  17. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id ;
  18. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id ;
  19. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id ; Stevens Thaio
  20. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id ;
  21. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id ; Stevens Thaio Principe Victor Aldeir
  22. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id ; Stevens Thaio Principe Victor Aldeir
  23. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id ; Stevens Thaio Principe Victor Aldeir
  24. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id ; Stevens Thaio Principe Victor Aldeir
  25. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id ; Stevens Thaio Principe Victor Aldeir
  26. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,????? as gerente_nome from tb_funcionarios f connect by f.gerente_id = prior f.id ;
  27. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,????? as gerente_nome from tb_funcionarios f connect by f.gerente_id = prior f.id ;
  28. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,prior f.nome as gerente_nome from tb_funcionarios f connect by f.gerente_id = prior f.id ;
  29. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,prior f.nome as gerente_nome from tb_funcionarios f connect by f.gerente_id = prior f.id ;
  30. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,prior f.nome as gerente_nome from tb_funcionarios f connect by f.gerente_id = prior f.id ;
  31. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id ;
  32. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id ; Chris Rafael Plauto Ricardo Stevens Thaio Principe Guto … Victor Aldeir Maia Pimentel Roberto …
  33. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id ; Chris Rafael Plauto Ricardo Stevens Thaio Principe Guto … Victor Aldeir Maia Pimentel Roberto …
  34. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id ; Chris Rafael Plauto Ricardo Stevens Thaio Principe Guto … Victor Aldeir Maia Pimentel Roberto …
  35. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id ; Chris Rafael Plauto Ricardo Stevens Thaio Principe Guto … Victor Aldeir Maia Pimentel Roberto … Root Node
  36. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id ; Chris Rafael Plauto Ricardo Stevens Thaio Principe Guto … Victor Aldeir Maia Pimentel Roberto … Root Node
  37. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.id = 3 ;
  38. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.id = 3 ;
  39. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.id = 3 ;
  40. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.id = 3 ;
  41. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.id = 3 ;
  42. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.id = 3 ;
  43. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.id = 3 ;
  44. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.id = 3 ;
  45. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.id = 3 ;
  46. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.id in (3, 45, 104) ;
  47. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.id in (3, 45, 104) ;
  48. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null ;
  49. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null ;
  50. Chris Rafael Plauto Ricardo Stevens Thaio Principe Guto … Victor

    Aldeir Maia Pimentel Roberto … 1 2 3 4 5 6
  51. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null ;
  52. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null ;
  53. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null ;
  54. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null ;
  55. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || id as tree from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null ;
  56. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.id as tree from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null ;
  57. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.id as tree from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null ;
  58. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.id as tree from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null ;
  59. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.id as tree from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null ;
  60. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || id as tree from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null ;
  61. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null ;
  62. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null ;
  63. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null order siblings by f.nome ;
  64. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null order by f.nome ;
  65. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null order by f.nome ;
  66. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null order by f.nome ; ????
  67. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null order by f.nome ;
  68. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null order by f.nome ;
  69. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null order siblings by f.nome ;
  70. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null order siblings by f.nome ;
  71. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null order siblings by f.nome ; x
  72. Outra forma de apresentar...
 (path) Chris Chris->Ricardo Chris->Ricardo->Plauto Chris->Ricardo->Plauto->Stevens Chris->Ricardo->Plauto->Stevens->Thaio

    Chris->Ricardo->Plauto->Stevens->Thaio->Aldeir Chris->Ricardo->Plauto->Stevens->Thaio->Principe Chris->Ricardo->Plauto->Stevens->Thaio->Victor Chris->Ricardo->Plauto->Stevens->Thaio->… Chris->Ricardo->Plauto->Guto …
  73. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree ,sys_connect_by_path(f.nome, '->') as path from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null order siblings by f.nome ;
  74. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree ,sys_connect_by_path(f.nome, '->') as path from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null order siblings by f.nome ;
  75. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree ,sys_connect_by_path(f.nome, '->') as path from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null order siblings by f.nome ;
  76. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree ,sys_connect_by_path(f.nome, '->') as path from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null order siblings by f.nome ;
  77. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree ,sys_connect_by_path(f.nome, '->') as path from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null order siblings by f.nome ;
  78. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree ,sys_connect_by_path(f.nome, '->') as path from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null order siblings by f.nome ;
  79. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree ,sys_connect_by_path(f.nome, '->') as path from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null order siblings by f.nome ;
  80. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree ,sys_connect_by_path(f.nome, '->') as path from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id is null order siblings by f.nome ;
  81. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree ,sys_connect_by_path(f.nome, '->') as path from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id = 3 order siblings by f.nome ;
  82. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree ,sys_connect_by_path(f.nome, '->') as path from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id = 3 order siblings by f.nome ; ERROR: ORA-01436: CONNECT BY loop in user data
  83. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree ,sys_connect_by_path(f.nome, '->') as path from tb_funcionarios f connect by f.gerente_id = prior f.id start with f.gerente_id = 3 order siblings by f.nome ;
  84. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree ,sys_connect_by_path(f.nome, '->') as path from tb_funcionarios f connect by nocycle f.gerente_id = prior f.id start with f.gerente_id = 3 order siblings by f.nome ;
  85. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree ,sys_connect_by_path(f.nome, '->') as path from tb_funcionarios f connect by nocycle f.gerente_id = prior f.id start with f.gerente_id is null order siblings by f.nome ;
  86. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree ,sys_connect_by_path(f.nome, '->') as path ,connect_by_cycle as is_cycle from tb_funcionarios f connect by nocycle f.gerente_id = prior f.id start with f.gerente_id = 3 order siblings by f.nome ;
  87. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree ,sys_connect_by_path(f.nome, '->') as path ,connect_by_iscycle as is_cycle from tb_funcionarios f connect by nocycle f.gerente_id = prior f.id start with f.gerente_id = 3 order siblings by f.nome ;
  88. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree ,sys_connect_by_path(f.nome, '->') as path ,connect_by_cycle as is_cycle from tb_funcionarios f connect by nocycle f.gerente_id = prior f.id start with f.gerente_id = 3 order siblings by f.nome ;
  89. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree ,sys_connect_by_path(f.nome, '->') as path ,connect_by_cycle as is_cycle from tb_funcionarios f connect by nocycle f.gerente_id = prior f.id start with f.gerente_id = 3 order siblings by f.nome ;
  90. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree ,sys_connect_by_path(f.nome, '->') as path ,connect_by_iscycle as is_cycle
 ,connect_by_isleaf as is_leaf ,connect_by_root f.id as root_id from tb_funcionarios f connect by nocycle f.gerente_id = prior f.id start with f.gerente_id is null order siblings by f.nome ;
  91. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree ,sys_connect_by_path(f.nome, '->') as path ,connect_by_iscycle as is_cycle
 ,connect_by_isleaf as is_leaf ,connect_by_root f.id as root_id from tb_funcionarios f connect by nocycle f.gerente_id = prior f.id start with f.gerente_id is null order siblings by f.nome ;
  92. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree ,sys_connect_by_path(f.nome, '->') as path ,connect_by_iscycle as is_cycle
 ,connect_by_isleaf as is_leaf ,connect_by_root f.id as root_id from tb_funcionarios f connect by nocycle f.gerente_id = prior f.id start with f.gerente_id is null order siblings by f.nome ;
  93. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree ,sys_connect_by_path(f.nome, '->') as path ,connect_by_iscycle as is_cycle
 ,connect_by_isleaf as is_leaf ,connect_by_root f.id as root_id from tb_funcionarios f connect by nocycle f.gerente_id = prior f.id start with f.gerente_id is null order siblings by f.nome ;
  94. select f.id as id ,f.nome as funcionario ,f.cargo as cargo

    ,f.gerente_id as gerente_id ,level ,lpad('.', (level-1), '.') || f.nome as tree ,sys_connect_by_path(f.nome, '->') as path ,connect_by_iscycle as is_cycle
 ,connect_by_isleaf as is_leaf ,connect_by_root f.id as root_id from tb_funcionarios f connect by nocycle f.gerente_id = prior f.id start with f.gerente_id is null order siblings by f.nome ;
  95. SELECT add_months(input, (level-1) * 12) as start_date ,add_months(input, level *

    12) as end_date FROM ( -- Set the input date here SELECT DATE'2012-02-01' as input FROM DUAL ) CONNECT BY add_months(input, (level-1) * 12) < Sysdate ;
  96. SELECT add_months(input, (level-1) * 12) as start_date ,add_months(input, level *

    12) as end_date FROM ( -- Set the input date here SELECT DATE'2012-02-01' as input FROM DUAL ) CONNECT BY add_months(input, (level-1) * 12) < Sysdate ;
  97. SELECT add_months(input, (level-1) * 12) as start_date ,add_months(input, level *

    12) as end_date FROM ( -- Set the input date here SELECT DATE'2012-02-01' as input FROM DUAL ) CONNECT BY add_months(input, (level-1) * 12) < Sysdate ;
  98. SELECT add_months(input, (level-1) * 12) as start_date ,add_months(input, level *

    12) as end_date FROM ( -- Set the input date here SELECT DATE'2012-02-01' as input FROM DUAL ) CONNECT BY add_months(input, (level-1) * 12) < Sysdate ;
  99. SELECT add_months(input, (level-1) * 12) as start_date ,add_months(input, level *

    12) as end_date FROM ( -- Set the input date here SELECT DATE'2012-02-01' as input FROM DUAL ) CONNECT BY add_months(input, (level-1) * 12) < Sysdate ; x está incluindo hoje, 2019-01-31