Solved

display id in connect prior sql

Posted on 2014-12-03
3
96 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
  • 2
3 Comments
 
LVL 24

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now