Home » SQL & PL/SQL » SQL & PL/SQL » SQL Query- Connect By (merged) (11g)
SQL Query- Connect By (merged) [message #684920] |
Tue, 28 September 2021 00:31  |
 |
sayan13
Messages: 17 Registered: July 2013 Location: Pune
|
Junior Member |
|
|
Hi,
I want to get the hierarchy of values(see comment below), but as per my query the results are returning as null
with table_a as
(
select 1 as seq, 'IP SC TOSAML:No port <> TOSA1>JKEL1_PDH:No port' as a, 'MCJ2G0109' as b,'TOSAML' as c,'9140227880213249394' as d,'Vlan 1' as e, 1 as rn, 3 as vlan_cnt from dual
UNION
select 1 as seq,'IP SC TOSAML:No port <> TOSA1>JKEL1_PDH:No port' as a, 'MCJ2G0109' as b,'TOSAML' as c,'9140227880213249394' as d,'Vlan 10' as e, 2 as rn, 3 as vlan_cnt from dual
UNION
select 1 as seq,'IP SC TOSAML:No port <> TOSA1>JKEL1_PDH:No port' as a, 'MCJ2G0109' as b,'TOSAML' as c,'9140227880213249394' as d,'Vlan 100' as e, 3 as rn, 3 as vlan_cnt from dual
)
select a,
b,
c,
rtrim(ltrim(sys_connect_by_path(e, ','), ','), ',') e, /*Results needed here as "vlan1, vlan10,vlan100" */
rn
from table_a
where rn = vlan_cnt
start with rn = 1
connect by prior rn = rn - 1
and prior c= c
group by seq, a, b, c, e, rn
order by a
Can anyone please assist how to do this?
|
|
|
SQL Query- Connect By [message #684921 is a reply to message #684920] |
Tue, 28 September 2021 00:31   |
 |
sayan13
Messages: 17 Registered: July 2013 Location: Pune
|
Junior Member |
|
|
Hi,
I want to get the hierarchy of values(see comment below), but as per my query the results are returning as null
with table_a as
(
select 1 as seq, 'IP SC TOSAML:No port <> TOSA1>JKEL1_PDH:No port' as a, 'MCJ2G0109' as b,'TOSAML' as c,'9140227880213249394' as d,'Vlan 1' as e, 1 as rn, 3 as vlan_cnt from dual
UNION
select 1 as seq,'IP SC TOSAML:No port <> TOSA1>JKEL1_PDH:No port' as a, 'MCJ2G0109' as b,'TOSAML' as c,'9140227880213249394' as d,'Vlan 10' as e, 2 as rn, 3 as vlan_cnt from dual
UNION
select 1 as seq,'IP SC TOSAML:No port <> TOSA1>JKEL1_PDH:No port' as a, 'MCJ2G0109' as b,'TOSAML' as c,'9140227880213249394' as d,'Vlan 100' as e, 3 as rn, 3 as vlan_cnt from dual
)
select a,
b,
c,
rtrim(ltrim(sys_connect_by_path(e, ','), ','), ',') e, /*Results needed here as "vlan1, vlan10,vlan100" */
rn
from table_a
where rn = vlan_cnt
start with rn = 1
connect by prior rn = rn - 1
and prior c= c
group by seq, a, b, c, e, rn
order by a
Can anyone please assist how to do this?
|
|
|
|
|
Goto Forum:
Current Time: Thu Mar 23 05:15:28 CDT 2023
|