13.05.2013 Views

Thanks for the question regarding "connect by ", versi

Thanks for the question regarding "connect by ", versi

Thanks for the question regarding "connect by ", versi

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

March 1, 2006 - 9am Central time zone Bookmark | Bottom | Top<br />

Reviewer: Tom Fox from Cincinnati, OH<br />

Tom, so what I'm getting out of <strong>the</strong> above query (repeating, not repeating, whatever) is that <strong>the</strong><br />

START WITH clause _must_ reference <strong>the</strong> left hand side of <strong>the</strong> CONNECT BY clause. Is this correct?<br />

--Tom<br />

Followup March 1, 2006 - 9am Central time zone:<br />

I don't even know what <strong>the</strong> "left hand side" of a <strong>connect</strong> <strong>by</strong> would be, so no.<br />

start with identifies <strong>the</strong> set of ROOT NODES.<br />

<strong>connect</strong> <strong>by</strong> builds a hierarchy of child nodes under each root.<br />

March 1, 2006 - 9am Central time zone Bookmark | Bottom | Top<br />

Reviewer: Tom Fox from Cincinnati, OH<br />

Yeah, I haven't finished my coffee yet. I meant <strong>the</strong> right hand side in my post above.<br />

--Tom<br />

Followup March 1, 2006 - 9am Central time zone:<br />

I don't know what <strong>the</strong> right hand side is ei<strong>the</strong>r.<br />

March 1, 2006 - 5pm Central time zone Bookmark | Bottom | Top<br />

Reviewer: Tom Fox from Cincinnati, OH<br />

Oh, you know, <strong>the</strong> right hand side.... Work with me here. :)<br />

In this query:<br />

scott@ORA8I.WORLD> select lpad(' ',level*2,' ')||ename ename, empno, mgr<br />

2 from emp<br />

3 START WITH MGR IS NULL<br />

4 CONNECT BY PRIOR EMPNO = MGR<br />

5 /<br />

What I was trying to ask: Does <strong>the</strong> START WITH clause (meaning MGR on line 3) have to reference <strong>the</strong><br />

right side of <strong>the</strong> CONNECT BY clause (line 4, in this case), in order <strong>for</strong> <strong>the</strong> tree to be <strong>for</strong>med<br />

correctly?<br />

In o<strong>the</strong>r terms, does START WITH always have to reference one of <strong>the</strong> fields in <strong>the</strong> CONNECT BY<br />

clause?<br />

Followup March 2, 2006 - 9am Central time zone:<br />

No, it does not have to.<br />

your start with simply identifies <strong>the</strong> rows that start hierarchies.<br />

You might want a tree <strong>for</strong> every MGR that has <strong>the</strong> JOB = 'X'<br />

so <strong>the</strong> start with would be referencing <strong>the</strong> EMPNO column and <strong>the</strong> JOB column (to find empnos that are<br />

mgrs and have a job = 'X' )<br />

Can we add salary to <strong>the</strong> query? March 2, 2006 - 1pm Central time zone Bookmark | Bottom | Top<br />

Reviewer: Mike from Dallas, TX<br />

Hi Tom,

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!