Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Alternate to sys connectbypath, connect by root

3574779Oct 17 2018 — edited Oct 18 2018

Hi all,

My requirement is as follows

i wan to get hierarchy format of data . we used connectby root and sys connect by path and wrote query but to completly fetch the data it is taking more than 2 hours time, as query is retrieving

lakhs of datafrom table. Is there any alternate method to show the data in hierachy format.please help

create table customer_master (sno number(10),customer_num number(10),prev_customer number(10));

insert into customer_master values(1,101,null);

insert into customer_master values(2,102,101);

insert into customer_master values(3,103,102);

insert into customer_master values(4,200,null);

insert into customer_master values(5,230,200);

format required: 101>102>103

200>230

query:

select customer_num,prev_customer,level,connect_by_root(customer_num)as original_customer,sys_connect_by_path(customer_num,'>')as customer_hierarchy

from(select customer_num,prev_customer from customer_master)

start with prev_customer is null

connect by prior customer_num=prev_customer;

output:-

pastedImage_1.png

Comments
Post Details
Added on Oct 17 2018
18 comments
1,681 views