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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

How to retrieve entire parent hierarchy level in SQL query?

Oracle_WalkerJan 4 2012 — edited Jun 26 2012
I'm using Oracle 10.2.0.4 version. I have a database table with the following structure,
CREATE TABLE SOME_TABLE
( 
  ID        NUMBER(10) PRIMARY KEY,
  PARENT    NUMBER(10)
)


ID    PARENT_ID

1        0 
2        1
3        1
4        2
5        4
6        4
100      0
Here '0' is root PARENT_ID. Say ID 5's parent is 4 & 4's parent is 2 & 2's parent is 1. How can i frame a SQL select query to which can eventually give me the output as '5/4/2/1' which is the parent hierarchy of ID 5. See the output doesn't contain the root PARENT_ID '0'

Edited by: Vel on Jan 5, 2012 12:20 AM
This post has been answered by BluShadow on Jun 26 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 24 2012
Added on Jan 4 2012
14 comments
1,289 views