<?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/blog/6533/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/blog/6533/oracle-11gr2-alternative-for-connect_by_isleaf-function-for-recursive-subquery-factoring-dedicated-to-anton</link>
	<description>Weblog for the AMIS Technology corner</description>
	<lastBuildDate>Sun, 14 Mar 2010 04:04:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Lucas</title>
		<link>http://technology.amis.nl/blog/6533/oracle-11gr2-alternative-for-connect_by_isleaf-function-for-recursive-subquery-factoring-dedicated-to-anton/comment-page-1#comment-349065</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-349065</guid>
		<description>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/blog/6533/oracle-11gr2-alternative-for-connect_by_isleaf-function-for-recursive-subquery-factoring-dedicated-to-anton/comment-page-1#comment-349032</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-349032</guid>
		<description>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/blog/6533/oracle-11gr2-alternative-for-connect_by_isleaf-function-for-recursive-subquery-factoring-dedicated-to-anton/comment-page-1#comment-349027</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-349027</guid>
		<description>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>
