<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Oracle 11gR2 &#8211; alternative for CONNECT_BY_ISLEAF function for Recursive Subquery Factoring (dedicated to Anton)</title>
	<atom:link href="http://technology.amis.nl/2009/11/14/oracle-11gr2-alternative-for-connect_by_isleaf-function-for-recursive-subquery-factoring-dedicated-to-anton/feed/" rel="self" type="application/rss+xml" />
	<link>http://technology.amis.nl/2009/11/14/oracle-11gr2-alternative-for-connect_by_isleaf-function-for-recursive-subquery-factoring-dedicated-to-anton/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=oracle-11gr2-alternative-for-connect_by_isleaf-function-for-recursive-subquery-factoring-dedicated-to-anton</link>
	<description></description>
	<lastBuildDate>Fri, 12 Apr 2013 10:04:09 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
	<item>
		<title>By: JÃ¼rgen Sieben</title>
		<link>http://technology.amis.nl/2009/11/14/oracle-11gr2-alternative-for-connect_by_isleaf-function-for-recursive-subquery-factoring-dedicated-to-anton/#comment-6025</link>
		<dc:creator>JÃ¼rgen Sieben</dc:creator>
		<pubDate>Sun, 25 Dec 2011 09:20:21 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=6533#comment-6025</guid>
		<description><![CDATA[I guess what you&#039;re looking for in first place could be achieved more securely with a scalar subquery like so:

with hierarchie (lvl, ename, empno, is_leaf) as (
select 1 lvl, ename, empno,
(select decode(count(*), 0, 1, 0)
from emp
where mgr = m.empno) is_leaf
from emp m
where mgr is null
union all
select h.lvl + 1, e.ename, e.empno,
(select decode(count(*), 0, 1, 0)
from emp
where mgr = e.empno) is_leaf
from hierarchie h, emp e
where h.empno = e.mgr)
search depth first by ename set sort_seq
select lvl, ename, is_leaf
from hierarchy;
To my understanding, this is somewhat easier to use. Whether this on the other hand is still performant is another question.
Best regards,
JÃ¼rgen]]></description>
		<content:encoded><![CDATA[<p>I guess what you&#8217;re looking for in first place could be achieved more securely with a scalar subquery like so:</p>
<p>with hierarchie (lvl, ename, empno, is_leaf) as (<br />
select 1 lvl, ename, empno,<br />
(select decode(count(*), 0, 1, 0)<br />
from emp<br />
where mgr = m.empno) is_leaf<br />
from emp m<br />
where mgr is null<br />
union all<br />
select h.lvl + 1, e.ename, e.empno,<br />
(select decode(count(*), 0, 1, 0)<br />
from emp<br />
where mgr = e.empno) is_leaf<br />
from hierarchie h, emp e<br />
where h.empno = e.mgr)<br />
search depth first by ename set sort_seq<br />
select lvl, ename, is_leaf<br />
from hierarchy;<br />
To my understanding, this is somewhat easier to use. Whether this on the other hand is still performant is another question.<br />
Best regards,<br />
JÃ¼rgen</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mette Stephansen</title>
		<link>http://technology.amis.nl/2009/11/14/oracle-11gr2-alternative-for-connect_by_isleaf-function-for-recursive-subquery-factoring-dedicated-to-anton/#comment-6024</link>
		<dc:creator>Mette Stephansen</dc:creator>
		<pubDate>Mon, 13 Dec 2010 14:34:09 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=6533#comment-6024</guid>
		<description><![CDATA[Hi there.

Very nice post :-)

How would I get the is_leaf if the ordering is not by depth, but by breadth ?

Regards
Mette]]></description>
		<content:encoded><![CDATA[<p>Hi there.</p>
<p>Very nice post <img src='http://technology.amis.nl/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>How would I get the is_leaf if the ordering is not by depth, but by breadth ?</p>
<p>Regards<br />
Mette</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lucas</title>
		<link>http://technology.amis.nl/2009/11/14/oracle-11gr2-alternative-for-connect_by_isleaf-function-for-recursive-subquery-factoring-dedicated-to-anton/#comment-6023</link>
		<dc:creator>Lucas</dc:creator>
		<pubDate>Wed, 18 Nov 2009 15:06:21 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=6533#comment-6023</guid>
		<description><![CDATA[Is what you are asking for just the root node for every leaf-node - it seems that way at least. Of course it is easy to add the root to every node returned from the query and then filter on is_leaf = 1. Something like:

WITH
  each_level  (empid, name, mgrid, lev, root) AS
  (
    SELECT empno, ename, mgr , 1, ename
    FROM emp
    WHERE mgr is null
    UNION ALL
    SELECT empno, ename, mgr, lev+1, root
    FROM each_level r, emp e
    WHERE r.empid = e.mgr
  )
SEARCH DEPTH FIRST BY mgrid SET seq
, leafNodes as
( select e.*
   from   each_level e
   where  case
    when (lev - lead(lev) over (order by seq)) &lt; 0
    then 0
    else 1
    end = 1
)
select ename
,        root top_manager
from  leafNodes


Or are you looking for something else?]]></description>
		<content:encoded><![CDATA[<p>Is what you are asking for just the root node for every leaf-node &#8211; it seems that way at least. Of course it is easy to add the root to every node returned from the query and then filter on is_leaf = 1. Something like:</p>
<p>WITH<br />
  each_level  (empid, name, mgrid, lev, root) AS<br />
  (<br />
    SELECT empno, ename, mgr , 1, ename<br />
    FROM emp<br />
    WHERE mgr is null<br />
    UNION ALL<br />
    SELECT empno, ename, mgr, lev+1, root<br />
    FROM each_level r, emp e<br />
    WHERE r.empid = e.mgr<br />
  )<br />
SEARCH DEPTH FIRST BY mgrid SET seq<br />
, leafNodes as<br />
( select e.*<br />
   from   each_level e<br />
   where  case<br />
    when (lev &#8211; lead(lev) over (order by seq)) &lt; 0<br />
    then 0<br />
    else 1<br />
    end = 1<br />
)<br />
select ename<br />
,        root top_manager<br />
from  leafNodes</p>
<p>Or are you looking for something else?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anton Scheffer</title>
		<link>http://technology.amis.nl/2009/11/14/oracle-11gr2-alternative-for-connect_by_isleaf-function-for-recursive-subquery-factoring-dedicated-to-anton/#comment-6022</link>
		<dc:creator>Anton Scheffer</dc:creator>
		<pubDate>Mon, 16 Nov 2009 15:27:30 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=6533#comment-6022</guid>
		<description><![CDATA[Of course I&#039;m satisfied! But can you use it to find the topmanager from every employee? Something like:

select emp.empid
     , emp.name
     , ( select mgr.name
         from emp mgr
         where connect_by_isleaf = 1
         connect by mgr.empid = prior mgr.mgr
         start with mgr.empid = emp.mgr
       ) top_manager
from emp emp]]></description>
		<content:encoded><![CDATA[<p>Of course I&#8217;m satisfied! But can you use it to find the topmanager from every employee? Something like:</p>
<p>select emp.empid<br />
     , emp.name<br />
     , ( select mgr.name<br />
         from emp mgr<br />
         where connect_by_isleaf = 1<br />
         connect by mgr.empid = prior mgr.mgr<br />
         start with mgr.empid = emp.mgr<br />
       ) top_manager<br />
from emp emp</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob van Wijk</title>
		<link>http://technology.amis.nl/2009/11/14/oracle-11gr2-alternative-for-connect_by_isleaf-function-for-recursive-subquery-factoring-dedicated-to-anton/#comment-6021</link>
		<dc:creator>Rob van Wijk</dc:creator>
		<pubDate>Sat, 14 Nov 2009 09:51:21 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=6533#comment-6021</guid>
		<description><![CDATA[Hi Lucas,

Brilliant idea! I just finished a session telling my audience there is no alternative for connect_by_isleaf. I&#039;ll have to revise that statement ...
By the way, cycle detection is still different from the connect-by syntax. Maybe you can even call it wrong but that&#039;s subjective. And did you compare execution plans and performance? If you do, you&#039;ll stick with connect-by. At least for some cases.

Regards,
Rob.]]></description>
		<content:encoded><![CDATA[<p>Hi Lucas,</p>
<p>Brilliant idea! I just finished a session telling my audience there is no alternative for connect_by_isleaf. I&#8217;ll have to revise that statement &#8230;<br />
By the way, cycle detection is still different from the connect-by syntax. Maybe you can even call it wrong but that&#8217;s subjective. And did you compare execution plans and performance? If you do, you&#8217;ll stick with connect-by. At least for some cases.</p>
<p>Regards,<br />
Rob.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
