C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to use Oracle PLSQL Connect By


Posted Date: 19 Sep 2008    Resource Type: Code Snippets    Category: SQL

Posted By: mohammad arshad       Member Level: Silver
Rating:     Points: 7



The Oracle PL/SQL "Connect By" syntax is very
valueable when extracting parent to child relationship
in your data. Suppose, an organization table
exists where three entity types are defined:
corporate, division, and branch. Suppose, each type
has an unique id, and within the organization table.

Lets build a table call organization

id type name
1 corporate abc hq

2 division division a
3 division division b
4 branch branch 1
5 branch branch 2
6 branch branch 3
7 branch branch 4

Lets build a table called organization_association that
defines the parent to child relationships

Parent_Id 1,1,2,2,3,3
Child_Id 2,3,4,5,6,7
If I start at the headquarters where
id=1

select id,type,name from organization
where
id in
(
select child_id from organization_association
where
start with parent_id in (1)
connect by prior child_id=parent_id
)

Produces
Organizations with ids equal to (2,3,4,5,6,7)

If I start with division id=2

select id,type,name from organization
where
id in
(
select child_id from organization_association
where
start with parent_id in (2)
connect by prior child_id=parent_id
)

Produces
Organizations with ids equal to (4,5)





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Use this query to implement SqlcacheDependency
Previous Resource: SQL function to split
Return to Discussion Resource Index
Post New Resource
Category: SQL


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use