SYS_CONNECT_BY_PATH [message #409740] |
Tue, 23 June 2009 15:57  |
Mahesh P
Messages: 69 Registered: September 2004
|
Member |
|
|
Hello Gurus,
I have a question on SYS_CONNECT_BY_PATH.
I am having the below query:
select SYS_CONNECT_BY_PATH(name, '\') path from dtree connect by prior dataid = parentid start with dataid = 2195674
and this will result me like:
folder A\folder B\Folder C\Folder D
folder A\folder B\Folder C\Folder E
folder A\folder B\Folder C\
folder A\folder B\
folder A\
and I am filtering it by level (level=4) and will result will be
folder A\folder B\Folder C\Folder D
I now thinking is there any inbuilt functions to split the path into separte columns like
folder A | folder B | Folder C | Folder D
.....
...
Or I will have to use the substr & instr functions..
Please throw some light..
Thanks,
Mahesh
|
|
|
|
Re: SYS_CONNECT_BY_PATH [message #409757 is a reply to message #409746] |
Tue, 23 June 2009 21:00   |
Mahesh P
Messages: 69 Registered: September 2004
|
Member |
|
|
Sorry, I hope you didn't get me.
I mean the path into a separate columns:
for example:
If we use the SYS_CONNECT_BY_PATH(name,'\') we will get the result as folder A\folder B\folder C\Folder D in one column. What I am looking is a way to separate this single column into multiple columns like folder A in one column, folder b in other column, folder C & folder D in other columns respectively..
I hope you get that now.
Thanks,
Mahesh
|
|
|
|
|
Re: SYS_CONNECT_BY_PATH [message #409896 is a reply to message #409774] |
Wed, 24 June 2009 06:58   |
Mahesh P
Messages: 69 Registered: September 2004
|
Member |
|
|
Hi Michel,
I am aware of the SUBSTR & INSTR functions but I am wondering if there is any other logic other than this because the SQL Query will be very messy if I have used SUBSTR, INSTR functions for 4 columns..
Thanks a lot.
Mahesh
|
|
|
|
|
Re: SYS_CONNECT_BY_PATH [message #618489 is a reply to message #409740] |
Sat, 12 July 2014 08:03  |
Solomon Yakobson
Messages: 3305 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
with t as (
select connect_by_root ename l1_ename,
lag(ename,2) over(order by 1) l2_ename,
prior ename l3_ename,
ename l4_ename,
level l
from emp
start with mgr is null
connect by mgr = prior empno
)
select l1_ename,
l2_ename,
l3_ename,
l4_ename
from t
where l = 4
/
L1_ENAME L2_ENAME L3_ENAME L4_ENAME
---------- ---------- ---------- ----------
KING JONES SCOTT ADAMS
KING ADAMS FORD SMITH
SQL>
SY.
|
|
|