Recursive SQL and information on different level

隐身守侯 提交于 2019-12-31 07:42:07

问题


Is it possible to display, in the same query, information concerning different level of recursivity ?

select LEVEL, ae2.CAB, ae2.NIVEAU, ae2.ENTITE, ae2.ENTITE_PARENT, ae2.libelle
from my_table ae2
where ae2.NIVEAU = 2
start with ae2.cab = 'XXX'
connect by prior ae2.entite_parent = ae2.entite

With this query I have (let's say) 4 levels of information about the entity above root 'XXX'

Is it possible to display root information at the same time?


回答1:


Yes, it's possible to use the CONNECT_BY_ROOT operator. For instance, if you wanted the cab of the parent your query would be:

select connect_by_root cab
      , level, cab, niveau, entite, entite_parent, libelle
   from my_table
  where niveau = 2
  start with cab = 'XXX'
connect by prior entite_parent = entite

You have to use a new operator for each column you want to select. You won't get information from a "different" level of recursivity using this operator, only from the root. If you want more you'll have to use recursive subquery factoring.



来源:https://stackoverflow.com/questions/25532304/recursive-sql-and-information-on-different-level

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!