473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Connect by Clause

5
Hi ,

I want to write a query which gives me tree structure as each node which has children should be displayed with its entire structure.Let me explain ....
1.I have hierarichal data for which I used connet by clause and I am getting tree structure.
2.Now I want to perform task as(in front end):I will have list of all nodes, I will select any one of node and it should show me tree after that node (considering start with clause with that selected node).
e.g.
T1
|_T2
|_T3 and T4
|_T31 |_T41

3.When I select T2,it should show me structure as T2,T3(with children) and T4 (with children)
4.when I select T3 then it should show me T3 and T31.
5.This is achieved with when I write start with = 'T2' but instead of this I want each node with its own tree.I want my query returning output as:
child_id Parent_id Node
T1 -1 T1

T2 T1 T2
T3 T2 T2
T31 T3 T2
T4 T2 T2
T41 T4 T2

T3 T2 T3
T31 T3 T3

T4 T2 T4
T41 T4 T4




Can anyone help in this?

Regards
KGP
Apr 12 '07 #1
4 3307
debasisdas
8,127 Expert 4TB
COLUMN EMPLOYEE FORMAT A20
----------------------------------------------------------------------
SELECT LEVEL,LPAD(' ',2*(LEVEL-1))||ENAME "EMPLOYEE" ,EMPNO,MGR FROM EMP
START WITH MGR IS NULL CONNECT BY PRIOR EMPNO=MGR
------------------------------------------------------------------

try the above query on EMP table of SCOTT schema

n for frontend i should know what is the frontend u r using for the purpose
Apr 13 '07 #2
KGP
5
Hi Debasis,
Thanks for your reply.
But my task is not simple.If you read my first mail: I have already done with tree structure using CONNECT BY clause.
I want tree straing with EACH PARENT node repeat in query output.
e.g.
If node 1 has 2 and 3 as child
node 2 has 21 and 22 as child &
node 3 has 31 and 32 as child then
my regular query will return:
child,parent
1,-1
2,1
21,2
22,2
3,2
31,3
32,3

but i want followingnew rows along with above 7 rows:
21,2
22,2
31,3
32,3

because my where clause will contain node for which I want display the tree and not the whole sincenode -1.
Apr 16 '07 #3
Hi as m new to oracle so could u please tell me some site where i could get
the sql problems.Basically,i need some questions so that i can apply my concepts on that.For practice purpose.hope u would help me on that.
Apr 27 '07 #4
debasisdas
8,127 Expert 4TB
Hi please try this code

Expand|Select|Wrap|Line Numbers
  1. SELECT LEVEL,LPAD(' ',2*(LEVEL-1))||ENAME "EMPLOYEE", EMPNO,MGR,SAL FROM EMP
  2. CONNECT BY PRIOR mgr=EMPNO
  3.  
try this on previous schema with previously specified column formatting
Apr 27 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Paul Rowe | last post by:
Hello; I am wondering if anyone knows of a way to issue the CONNECT BY clause on data that contains cycles? I have a business requirement that specifies that cycles could be present in the data...
5
by: D. Dante Lorenso | last post by:
I have a simple table that I'd like to query to pull out a heirarchy from a tree relationship. What is the best way to do this without a 'CONNECT BY' clause like Oracle has? Example mytable...
12
by: Mikito Harakiri | last post by:
I wonder if WITH RECURSIVE MaryAncestor(anc,desc) AS ( (SELECT parent as anc, child as desc FROM ParentOf WHERE desc = "Mary") UNION (SELECT A1.anc, A2.desc FROM MaryAncestor A1, MaryAncestor...
2
by: klh | last post by:
We use DB2 Connect v 7.2 FP7 in Windows NT hitting a OS/390 DB2 v7.1 database. We have a Websphere (java) application that issues dynamic SQL. Most of the time when we issue dynamic SQL SELECT...
3
by: Fabian Knopf | last post by:
Hi friends, i have a unix machine PC1 where a database is running ( IBM DB2 V8.1 ) . Then i have another machine PC2 i installed there also ( IBM DB2 V8.1 ). On PC2 i installed unixODBC. To...
4
by: banz | last post by:
Hello I have a problem to resolve: I wrote a Perlscript which caches data from a server (local on my machine) I would like to have a other connection to a remote server but I don't know how to...
2
by: David Parker | last post by:
I know this question has been discussed, probably multiple times, but I can't seem to access archives.postgresql.org today.... I need to select all the rows in a table with two fields: parent_id...
0
by: Hash123 | last post by:
Hi All, Does anyone know what is the equivalent query for 1 SELECT name, salary 2 FROM emp 3 START WITH name = 'Goyal' 4 CONNECT BY PRIOR empid = mgrid in DB2
0
by: KGP | last post by:
Hi , I want to write a query which gives me tree structure as each node which has children should be displayed with its entire structure.Let me explain .... 1.I have hierarichal data for which I...
2
by: dilippanda | last post by:
Hi, Can anyone please guide me the use of connect by clause with one example? Awaiting for your reply. Thanks, Dilip
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.