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.

c_NAME VARCHAR2(40),<br />

c_ID VARCHAR2(10),<br />

c_MGRID VARCHAR2(10),<br />

c_MGRNAME VARCHAR2(40)<br />

);<br />

Typical Data is<br />

insert into EMPINFO VALUES ('A','HR','','','JASON BICKER','0000001','','');<br />

insert into EMPINFO VALUES ('A','HR','','','NANCY WALTER','0400001','0000001','JASON BICKER');<br />

insert into EMPINFO VALUES ('','MF','NAN3005','WIN','NANCY WALTER','0400001','','');<br />

insert into EMPINFO VALUES ('','MF','NAN3005','UNIX','NANCY WALTER','0400001','','');<br />

insert into EMPINFO VALUES ('A','HR','','','ADAM BRYAN','0400002','0000001','JASON BICKER');<br />

insert into EMPINFO VALUES ('','MF','BRY0034','WIN','ADAM BRYAN','0400002','','');<br />

insert into EMPINFO VALUES ('A','HR','','','STING CORY','0400003','0400002','ADAM BRYAN');<br />

insert into EMPINFO VALUES ('','MF','STI4040','UNIX','STING CORY','0400003','','');<br />

For example I want to display all records of NANCY WALTER. The c_MGRID is blank <strong>for</strong> 2nd and 3rd<br />

record of NANCY WALTER. Similar structure will follow <strong>for</strong> o<strong>the</strong>r records as well.<br />

Regards,<br />

Rao<br />

Followup October 10, 2006 - 8pm Central time zone:<br />

if nancy walker doesn't have a manager, how is "she" in <strong>the</strong> hierarchy????<br />

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

Reviewer: A reader<br />

This table is kind of a master table that includes employee and its manager and <strong>the</strong><br />

systems(Unix/Windows) and userids <strong>the</strong> employee has on it.<br />

Nancy Walker has a manager whose c_MGRID is populated <strong>for</strong> <strong>the</strong> 1st row. But <strong>the</strong> 2nd and 3rd row of<br />

Nancy Walker shows<br />

<strong>the</strong> system and <strong>the</strong> userid's she has access to. c_MGRID of this 2nd and 3rd row is empty. Is it<br />

possible to include <strong>the</strong>se rows in <strong>the</strong> hierarchy as well similar to "start with .... <strong>connect</strong> <strong>by</strong><br />

prior"<br />

Followup October 11, 2006 - 3pm Central time zone:<br />

need more details, can <strong>the</strong>re be two (or zero, or more than two) records <strong>for</strong> nancy in <strong>the</strong>re with<br />

c_mgrid filled in? would <strong>the</strong>y have <strong>the</strong> same value?<br />

October 11, 2006 - 4pm Central time zone Bookmark | Bottom | Top<br />

Reviewer: A reader<br />

For a user<br />

a) only one record wherver c_mgrid is filled. This will always be <strong>the</strong>re when he/she joins <strong>the</strong><br />

company.<br />

b) 0 or more records wherever c_mgrid is not filled. Rows will be <strong>the</strong>re only if user has access to<br />

any Windows/Unix/Mainframe systems and has an userid on it.<br />

Followup October 11, 2006 - 8pm Central time zone:<br />

use this as your "source" to <strong>connect</strong> <strong>by</strong> on:<br />

ops$tkyte%ORA10GR2> select c_name, max( c_mgrid) over (partition <strong>by</strong> c_name) mgrid<br />

2 from empinfo;<br />

C_NAME MGRID<br />

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

ADAM BRYAN 0000001<br />

ADAM BRYAN 0000001

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

Saved successfully!

Ooh no, something went wrong!