Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
SQL Server 119
#SQLServer 88
Oracle 70
#SQL SERVER 35
BRH 31
SQL Server 2012 29
denali 23
#TSQL 19
TSQL 19
C# 15

Archive · View All
October 2011 31
November 2011 30
September 2011 30
August 2011 18
December 2011 15
July 2011 13
June 2011 8
May 2012 4
April 2012 3
January 2010 3

Day 33: Tree Structure query by using Oracle's Connect By clause

Oct 16 2011 8:13AM by Niladri Biswas   

Let Us Learn Oracle - Part 33 of N [ Tree Structure query by using Oracle's Connect By clause ]

This clause creates a report on inheritence tree structure data.

We will look into the TSql Challenge #8 and will solve that by using this clause

SQL> Select LPAD(' ' ,Level * 4) || EMPNAME "Employee Hierarchy"
  2   From tSqlChallenge8 
  3   Start With REPORTSTO Is Null And EMPNAME = 'Jacob'
  4   Connect By Prior EMPID = REPORTSTO;

Employee Hierarchy
--------------------------------------------------------------------------------
    Jacob
        Jess
        Steve
            John
        Bob
            Michael
            Paul

7 rows selected.

The position of PRIOR with respect to the Connect By expression determines which expression identifies the root and which occupies the branches. The LEVEL pseudo-column is an indication of how deep the tree is. Oracle can handle queries with a depth of upto 255 levels. The Start With clause is used to specify the start of the tree. More than one record can match the starting condition.

Instead of hardcoding the Manager name, we can use bind variable and pass the value at runtime


SQL>  Select LPAD(' ' ,Level * 4) || EMPNAME "Employee Hierarchy"
  2    From tSqlChallenge8 
  3    Start With REPORTSTO Is Null And EMPNAME = &EmpName
  4  Connect By Prior EMPID = REPORTSTO;
Enter value for empname: 'Jacob'
old   3:   Start With REPORTSTO Is Null And EMPNAME = &EmpName
new   3:   Start With REPORTSTO Is Null And EMPNAME = 'Jacob'

Employee Hierarchy
--------------------------------------------------------------------------------
    Jacob
        Jess
        Steve
            John
        Bob
            Michael
            Paul

7 rows selected.

We have define a bind variable &EmpName ( any variable name prefixed with ampersand(&) is a bind variable). It will prompt to enter the value at runtime.

For getting a complete report we can do the below

SQL>  Select LPAD(' ' ,Level * 4) || EMPNAME "Employee Hierarchy"
  2    From tSqlChallenge8 
  3    Start With REPORTSTO Is Null
  4  Connect By Prior EMPID = REPORTSTO;

Employee Hierarchy
--------------------------------------------------------------------------------
    Jacob
        Jess
        Steve
            John
        Bob
            Michael
            Paul
    Rui
        Smith
            Lana
            Johnson

        Bobbey
            Mic
            Stev
    Jacobson
        Steffi
            Paulson
        Bracha
            Jessica

19 rows selected.

Hope this is helpful. Thanks for reading

Tags: #SQLServer, SQL Server, Oracle,


Niladri Biswas
7 · 21% · 6710
1
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

"Day 33: Tree Structure query by using Oracle's Connect By clause " rated 5 out of 5 by 1 readers
Day 33: Tree Structure query by using Oracle's Connect By clause , 5.0 out of 5 based on 1 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]