Solved

display id in connect prior sql

Posted on 2014-12-03
3
109 Views
Last Modified: 2014-12-20
hi how can i diplsay the id of

obj_name

obj_parent

obj_child

and make sure there is no duplicate in obj_name column


WITH hierarchical AS (  

      SELECT  obj_parent

            , li.obj_name  

           , li.obj_type  

           , li.obj_title              , li.DESCRIPTION    

            , LEVELAS lvl

           , SYS_CONNECT_BY_PATH(li.obj_name, '/')paths    

        FROM object_list li  

        LEFTJOIN cal_erd er ON (li.cal_objid = er.obj_child)

           START WITH obj_parent IS NULL  

          CONNECTBY    

                  NOCYCLE PRIOR cal_objid = obj_parent

                   )                        

, childs_parents AS (

              SELECT  obj_name

                    , LEAD(obj_name) OVER(PARTITION BY substr(paths, 1 ,

                                          CASEWHEN INSTR(paths, '/', 1, 2) > 0

                                               THEN INSTR(paths, '/', 1, 2) -1

                                                ELSE LENGTH(paths)

                                           END)ORDERBY paths) AS child_name

                    , substr(paths,                          

                                  INSTR(paths, '/', 1, CASEWHEN lvl > 1 THEN lvl-1 END) + 1 ,    

                                  INSTR(paths, '/', 1, CASEWHEN lvl > 1 THEN lvl END)                      

                                - INSTR(paths, '/', 1, CASEWHEN lvl > 1 THEN lvl-1 END) - 1 ) AS parent_name

                   , obj_type    

                    , obj_title  

                    , DESCRIPTION    

                  

              FROM hierarchical

              )

SELECT *  

  FROM childs_parents;

Open in new window


i what to display value like this
OBJ_CHILD    CHILD_ID    OBJ_ID    OBJ_NAME         OBJ_PARENT    PARENT_ID

ThirdObject      1194         1 193        SecondObject    MainObject    1 192

FourthObject    1195        1 194        ThirdObject        SecondObject   1 193

                          1195                               FourthObject    ThirdObject    1 194

                         1196                               FirthObject      

SecondObject  1193              1 192       MainObject
0
Comment
Question by:chalie001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
chaau earned 500 total points
ID: 40479671
You need to bring these IDs to the hierarchical cte, and then bring them over to the childs_parents cte, like this:
WITH hierarchical AS (  
      SELECT  obj_parent
            , li.obj_name  
           , li.obj_type  
           , li.obj_title              , li.DESCRIPTION    
            , LEVELAS lvl
           , SYS_CONNECT_BY_PATH(li.obj_name, '/')paths
           , li.cal_objid obj_id
        FROM object_list li  
        LEFTJOIN cal_erd er ON (li.cal_objid = er.obj_child)
           START WITH obj_parent IS NULL  
          CONNECTBY    
                  NOCYCLE PRIOR cal_objid = obj_parent
                   )                        
, childs_parents AS (
              SELECT  obj_name
                    , LEAD(obj_name) OVER(PARTITION BY substr(paths, 1 ,
                                          CASE WHEN INSTR(paths, '/', 1, 2) > 0
                                               THEN INSTR(paths, '/', 1, 2) -1
                                                ELSE LENGTH(paths)
                                           END)ORDERBY paths) AS child_name
                    , substr(paths,                          
                                  INSTR(paths, '/', 1, CASEWHEN lvl > 1 THEN lvl-1 END) + 1 ,    
                                  INSTR(paths, '/', 1, CASEWHEN lvl > 1 THEN lvl END)                      
                                - INSTR(paths, '/', 1, CASEWHEN lvl > 1 THEN lvl-1 END) - 1 ) AS parent_name
                   , obj_type    
                    , obj_title  
                    , DESCRIPTION    
                    , obj_id
                    , LEAD(obj_id) OVER(PARTITION BY substr(paths, 1 ,
                                          CASE WHEN INSTR(paths, '/', 1, 2) > 0
                                               THEN INSTR(paths, '/', 1, 2) -1
                                                ELSE LENGTH(paths)
                                           END)ORDERBY paths) AS child_id
                    , obj_parent parent_id
              FROM hierarchical
              )
SELECT *  FROM childs_parents;

Open in new window

0
 

Author Closing Comment

by:chalie001
ID: 40506375
correct
0
 

Author Comment

by:chalie001
ID: 40510894
hi I will like to concaternate connect prior return values to look like this from above query
    Obj_Name       child_name      Parent_name

    MainObject     ThirdObject    (null)

    SecondObject   FourthObject    MainObject

    FourthObject   ThirdObject     SecondObject

    ThirdObject    ThirdObject     SecondObject,MainObject

or
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question