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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>connect</strong> <strong>by</strong> prior empno = mgr<br />

/<br />

ENAME DNAME PNAME<br />

------------------------------ -------------- --------------------<br />

**KING ACCOUNTING<br />

****CLARK ACCOUNTING<br />

******MILLER ACCOUNTING Engineering<br />

****JONES RESEARCH<br />

******FORD RESEARCH<br />

********SMITH RESEARCH Maintenance<br />

--clean up<br />

drop table schedules;<br />

alter table emp drop column projno;<br />

drop table projects;<br />

Won't <strong>connect</strong> <strong>by</strong> entire table March 13, 2006 - 5pm Central time zone Bookmark | Bottom | Top<br />

Reviewer: Mike from Dallas, TX<br />

Tom,..<br />

I didn't intend to <strong>connect</strong> <strong>by</strong> <strong>the</strong> entire table, only in this exercise because <strong>the</strong> tickets table<br />

only has records were interested in, <strong>the</strong> ticket table does have a current_lifecycle_state column to<br />

it.<br />

Also, not every entity has tickets. The first query show this where clause. Sorry I didn't have it<br />

in <strong>the</strong> second query.<br />

The task I am trying to accomplish is not to have <strong>the</strong> query go completely down <strong>the</strong> entity table<br />

using <strong>connect</strong> <strong>by</strong> <strong>for</strong> every record resulting from <strong>the</strong> outer <strong>connect</strong> <strong>by</strong>. For Example,..<br />

Level1-<br />

|_<br />

| Level2_<br />

| |_Level3<br />

| |_Level3<br />

| |_Level3<br />

|_Level2_<br />

| |_Level3<br />

| |_Level3_<br />

| |_Level4<br />

| |_Level4<br />

|_Level2_<br />

For each entity, <strong>the</strong>re may/may not be opened tickets in <strong>the</strong> ticket table. One could create a view<br />

on tickets <strong>for</strong> each entity easily using <strong>the</strong> <strong>connect</strong> <strong>by</strong> and scalar subquery that returns <strong>the</strong> number<br />

of open tickets <strong>for</strong> that entity alone.<br />

Would <strong>the</strong>re be a better way to sum up <strong>the</strong>se numbers from <strong>the</strong> bottom up and <strong>the</strong>re<strong>for</strong>e get a faster<br />

return using less resources than having to use <strong>the</strong> <strong>connect</strong> <strong>by</strong> in <strong>the</strong> scalar subquery.<br />

I hope I was a bit clearer.<br />

Mike<br />

Please Help May 6, 2006 - 5pm Central time zone Bookmark | Bottom | Top<br />

Reviewer: Isam from Jordan<br />

Hi Tom,<br />

How can I query all Employees ( lets say whose sal >=3000 ) and <strong>the</strong>ir managers.<br />

I used <strong>the</strong> follwing but <strong>the</strong> result is not what I want<br />

select EMPNO,SUBSTR(rpad('*',2*level,'*' ) || ENAME,1,30), MGR,SAL FROM EMP<br />

START WITH MGR IN (SELECT X.EMPNO FROM EMP X WHERE X.SAL>=3000)<br />

CONNECT BY PRIOR EMPNO = MGR<br />

The Result is :

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

Saved successfully!

Ooh no, something went wrong!