Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8245003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:02:58+00:00 2026-06-07T22:02:58+00:00

1 Create table like this CREATE TABLE oracle_connet_by_test ( item_id NUMBER PRIMARY KEY, parent_id

  • 0

1 Create table like this

    CREATE TABLE oracle_connet_by_test (
    item_id NUMBER PRIMARY KEY,
    parent_id NUMBER,
    item_desc VARCHAR2(8));

    INSERT INTO oracle_connet_by_test VALUES(1, 0, 'AAA');
    INSERT INTO oracle_connet_by_test VALUES(2, 0, 'BBB');
    INSERT INTO oracle_connet_by_test VALUES(3, 1, 'CCC');
    INSERT INTO oracle_connet_by_test VALUES(4, 2, 'DDD');
    INSERT INTO oracle_connet_by_test VALUES(5, 1, 'EEE');
    INSERT INTO oracle_connet_by_test VALUES(6, 3, 'FFF');
    INSERT INTO oracle_connet_by_test VALUES(7, 3, 'GGG');
    commit;

2 When I ran this script, the output will be

    SQL> SELECT LEVEL,
      2         ITEM_ID,
      3         PARENT_ID, LPAD(' ', 4 * (LEVEL - 1)) || ITEM_DESC AS ITEM_DESC
      4    FROM ORACLE_CONNET_BY_TEST
      5   START WITH parent_Id = 0
      6  CONNECT BY PRIOR ITEM_ID = PARENT_ID
      7  ;

         LEVEL    ITEM_ID  PARENT_ID ITEM_DESC
    ---------- ---------- ---------- -----------
             1          1          0 AAA
             2          3          1     CCC
             3          6          3         FFF
             3          7          3         GGG
             2          5          1     EEE
             1          2          0 BBB
             2          4          2     DDD

3 The QUESTION: If I want this result, how should I write the code?

         LEVEL    ITEM_ID  PARENT_ID ITEM_DESC        SUPER_ID
    ---------- ---------- ---------- ---------------- ----------
             1          1          0 AAA              1
             2          3          1     CCC          1
             3          6          3         FFF      1
             3          7          3         GGG      1
             2          5          1     EEE          1
             1          2          0 BBB              2
             2          4          2     DDD          2
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T22:02:59+00:00Added an answer on June 7, 2026 at 10:02 pm

    use connect_by_root:

    SELECT LEVEL,
               ITEM_ID,
               PARENT_ID, LPAD(' ', 4 * (LEVEL - 1)) || ITEM_DESC AS ITEM_DESC
               , connect_by_root item_id  AS SUPER_ID
          FROM ORACLE_CONNET_BY_TEST
         START WITH parent_Id = 0
        CONNECT BY PRIOR ITEM_ID = PARENT_ID
        ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have something like this: create table account ( id int identity(1,1) primary key,
I created a table like this CREATE TABLE pull_dtl ( source_schema VARCHAR2(4000), source_tablename VARCHAR2(4000),
Something like: create table Employee( ID int primary key, Name nvarchar(200) IDArea int foreign
(Using Oracle) I have a table with key/value pairs like this: create table MESSAGE_INDEX
I have two tables like this create table A_DUMMY ( TRADE_ID VARCHAR2(16) TRADE_DATA VARCHAR2(500)
I have a situation like this: create table a( a_id number(38) not null, constraint
I have a table like this: CREATE TABLE book_info ( book_id VARCHAR(32) not null,
I've created a table like this : create table tbl( address varchar(5000)); If i
I am creating table like this: CREATE TABLE foobar (id uniqueidentifier, foo text, bar
If my table looks like this: CREATE TABLE `daily_individual_tracking` ( `daily_individual_tracking_id` int(10) unsigned NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.