SQL Language (MOSC)

MOSC Banner

Traverse to Parent for the given child in SQL

edited May 4, 2020 4:22AM in SQL Language (MOSC) 2 commentsAnswered ✓

Hi,

I have a table with below structure and data.

{Code}

CREATE TABLE A

(

   CHILD_ID      NUMBER,

   EVALUE        VARCHAR2(100 CHAR),

   PARENT_ID     NUMBER

)

INSERT INTO A  VALUES ( 3803783, 'BLADE', 3803772);

INSERT INTO A  VALUES ( 3803772, 'PE', 3803767);

INSERT INTO A  VALUES ( 3803767, 'MEC', 0);

INSERT INTO A  VALUES ( 3847134, 'DE', 3803767);

INSERT INTO A  VALUES ( 3803767, 'MEC', 0);

{code}

I want output string as 'MEC || PE || BLADE' if I start with Child 3803783, similarly I should get 'MEC || DE' if I start with child 3847134

Could you please help me with SQL query.

Regards,

Laxman

Howdy, Stranger!

Log In

To view full details, sign in to My Oracle Support Community.

Register

Don't have a My Oracle Support Community account? Click here to get started.

Category Leaderboard

Top contributors this month

New to My Oracle Support Community? Visit our Welcome Center

MOSC Help Center