Solved

display id in connect prior sql

Posted on 2014-12-03
3
92 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
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 shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Via a live example, show how to take different types of Oracle backups using RMAN.

762 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

22 Experts available now in Live!

Get 1:1 Help Now