Parent                             Child                             
---------------------------------- ----------------------------------
World                              Europe                            
World                              North America                     
Europe                             France                            
France                             Paris                             
North America                      United States                     
North America                      Canada                            
United States                      New York                          
United States                      Washington                        
New York                           New York City                     
Washington                         Redmond                           
----------------------------------------------
如何实现下边的查询结果:::????World
   North America
      Canada
      United States
         Washington
            Redmond
         New York
            New York City
   Europe
      France
         Paris

解决方案 »

  1.   

    select level,name from tbname start with Parent = 'World' connect by prior child=parent;
      

  2.   

    試一下這個:
    select lpad(Parent,length(Parent)+level) col from tbname connect by prior child=parent;
      

  3.   

    select lpad(Parent,length(Parent)+level) col from tbname
     start with parent is not null
     connect by child=prior parent;
      

  4.   

    select lpad(Parent,length(Parent)+level,' ') col from tbname connect by prior child=parent;
      

  5.   

    SELECT  LPAD('  ',2*(LEVEL - 1)) || lname "Name" 
    FROM dbname 
    START WITH Parent IS 'World'
    CONNECT BY PRIOR Child= Parent ;
      

  6.   

    SELECT  LPAD('  ',2*(LEVEL - 1)) || lname "Name" 
    FROM dbname 
    START WITH Parent = 'World'
    CONNECT BY PRIOR Child= Parent ;