SlideShare una empresa de Scribd logo
1 de 12
Hierarchical Retrieval  http://ecomputernotes.com
Objectives  After completing this lesson, you should be able to do the following:  "  Interpret the concept of a hierarchical query  "  Create a tree-structured report  "  Format hierarchical data  "  Exclude branches from the tree structure  http://ecomputernotes.com
Sample Data from the   EMPLOYEES  Table  http://ecomputernotes.com
Natural Tree Structure  EMPLOYEE_ID = 100   (Parent)  King  MANAGER_ID = 100   (Child)  Mourgos  Kochhar  De Hann  Hartstei  Zlotkey  alen   Higgins  Hunold  Rajs   Davies   Matos  Vargas  Fay  Abel  Taylor  Grant  Gietz Ernst  Lorentz  http://ecomputernotes.com
Hierarchical Queries  SELECT [LEVEL],   column ,   expr ... FROM  table  [WHERE   condition(s) ] [START WITH   condition(s) ]  [CONNECT BY PRIOR   condition(s) ] ;  WHERE   condition :  expr comparison_operator expr  http://ecomputernotes.com
Walking the Tree  Starting Point  "  Specifies the condition that must be met  "  Accepts any valid condition  START WITH   column1  =   value  Using the   EMPLOYEES   table, start with the employee  whose last name is Kochhar.  ...START WITH   last_name  =   'Kochhar'  http://ecomputernotes.com
Walking the Tree  CONNECT BY PRIOR   column1=   column2  Walk from the top down, using the   EMPLOYEES  table.  ... CONNECT BY PRIOR employee_id = manager_id  Direction  Top down  Column1 = Parent Key  Column2 = Child Key  Bottom up  Column1 = Child Key Column2 = Parent Key  http://ecomputernotes.com
Walking the Tree: From the Bottom Up  SELECT employee_id, last_name, job_id, manager_id  FROM  employees  START  WITH  employee_id = 101  CONNECT BY PRIOR manager_id = employee_id ;  http://ecomputernotes.com
Walking the Tree:  From the Top Down  SELECT  last_name||' reports to '||  PRIOR  last_name "Walk Top Down"  FROM  employees  START  WITH last_name = 'King'  CONNECT BY PRIOR employee_id = manager_id ;  «  http://ecomputernotes.com
Ranking Rows with the   LEVEL  Pseudocolumn  Level 1  root/parent  King  Level 2  parent/child  Mourgos  chhar  De Hann  Hartstein  Zlotkey  Level 3  parent/ch  en   Higgins   Hunold  /leaf  Rajs Davies  Matos  Vargas  Fay  Abel  Taylor  Grant  Level 4  Gietz Ernst  Lorentz  leaf  http://ecomputernotes.com
Formatting Hierarchical Reports Using  LEVEL   and   LPAD  Create a report displaying company management levels, beginning with the highest level and indenting each of the following levels.  OLUMN org_chart FORMAT A12  ELECT LPAD(last_name, LENGTH(last_name)+(LEVEL*2)-2,'_')  AS org_chart  ROM  employees  TART WITH last_name='King'  ONNECT BY PRIOR employee_id=manager_id  http://ecomputernotes.com
Pruning Branches  Use the   WHERE   clause  Use the   CONNECT BY   clause  to eliminate a node.  to eliminate a branch.  HERE last_name != 'Higgins'  CONNECT BY PRIOR employee_id = manager_id AND last_name != 'Higgins'  Kochhar  Kochhar  Whalen  Higgins  Whalen  Higgins  Gietz  Gietz  http://ecomputernotes.com

Más contenido relacionado

Más de ecomputernotes

computer notes - Data Structures - 15
computer notes - Data Structures - 15computer notes - Data Structures - 15
computer notes - Data Structures - 15
ecomputernotes
 
Computer notes - Including Constraints
Computer notes - Including ConstraintsComputer notes - Including Constraints
Computer notes - Including Constraints
ecomputernotes
 
Computer notes - Date time Functions
Computer notes - Date time FunctionsComputer notes - Date time Functions
Computer notes - Date time Functions
ecomputernotes
 
Computer notes - Subqueries
Computer notes - SubqueriesComputer notes - Subqueries
Computer notes - Subqueries
ecomputernotes
 
Computer notes - Other Database Objects
Computer notes - Other Database ObjectsComputer notes - Other Database Objects
Computer notes - Other Database Objects
ecomputernotes
 
computer notes - Data Structures - 28
computer notes - Data Structures - 28computer notes - Data Structures - 28
computer notes - Data Structures - 28
ecomputernotes
 
computer notes - Data Structures - 19
computer notes - Data Structures - 19computer notes - Data Structures - 19
computer notes - Data Structures - 19
ecomputernotes
 
computer notes - Data Structures - 31
computer notes - Data Structures - 31computer notes - Data Structures - 31
computer notes - Data Structures - 31
ecomputernotes
 
computer notes - Data Structures - 4
computer notes - Data Structures - 4computer notes - Data Structures - 4
computer notes - Data Structures - 4
ecomputernotes
 
computer notes - Data Structures - 13
computer notes - Data Structures - 13computer notes - Data Structures - 13
computer notes - Data Structures - 13
ecomputernotes
 
Computer notes - Advanced Subqueries
Computer notes -   Advanced SubqueriesComputer notes -   Advanced Subqueries
Computer notes - Advanced Subqueries
ecomputernotes
 
Computer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group FunctionsComputer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group Functions
ecomputernotes
 
computer notes - Data Structures - 16
computer notes - Data Structures - 16computer notes - Data Structures - 16
computer notes - Data Structures - 16
ecomputernotes
 
computer notes - Data Structures - 22
computer notes - Data Structures - 22computer notes - Data Structures - 22
computer notes - Data Structures - 22
ecomputernotes
 
computer notes - Data Structures - 35
computer notes - Data Structures - 35computer notes - Data Structures - 35
computer notes - Data Structures - 35
ecomputernotes
 
computer notes - Data Structures - 36
computer notes - Data Structures - 36computer notes - Data Structures - 36
computer notes - Data Structures - 36
ecomputernotes
 
Computer notes - Enhancements to the GROUP BY Clause
Computer notes - Enhancements to the GROUP BY ClauseComputer notes - Enhancements to the GROUP BY Clause
Computer notes - Enhancements to the GROUP BY Clause
ecomputernotes
 
Computer notes - Manipulating Data
Computer notes - Manipulating DataComputer notes - Manipulating Data
Computer notes - Manipulating Data
ecomputernotes
 
Computer notes - Writing Basic SQL SELECT Statements
Computer notes - Writing Basic SQL SELECT StatementsComputer notes - Writing Basic SQL SELECT Statements
Computer notes - Writing Basic SQL SELECT Statements
ecomputernotes
 
computer notes - Data Structures - 14
computer notes - Data Structures - 14computer notes - Data Structures - 14
computer notes - Data Structures - 14
ecomputernotes
 

Más de ecomputernotes (20)

computer notes - Data Structures - 15
computer notes - Data Structures - 15computer notes - Data Structures - 15
computer notes - Data Structures - 15
 
Computer notes - Including Constraints
Computer notes - Including ConstraintsComputer notes - Including Constraints
Computer notes - Including Constraints
 
Computer notes - Date time Functions
Computer notes - Date time FunctionsComputer notes - Date time Functions
Computer notes - Date time Functions
 
Computer notes - Subqueries
Computer notes - SubqueriesComputer notes - Subqueries
Computer notes - Subqueries
 
Computer notes - Other Database Objects
Computer notes - Other Database ObjectsComputer notes - Other Database Objects
Computer notes - Other Database Objects
 
computer notes - Data Structures - 28
computer notes - Data Structures - 28computer notes - Data Structures - 28
computer notes - Data Structures - 28
 
computer notes - Data Structures - 19
computer notes - Data Structures - 19computer notes - Data Structures - 19
computer notes - Data Structures - 19
 
computer notes - Data Structures - 31
computer notes - Data Structures - 31computer notes - Data Structures - 31
computer notes - Data Structures - 31
 
computer notes - Data Structures - 4
computer notes - Data Structures - 4computer notes - Data Structures - 4
computer notes - Data Structures - 4
 
computer notes - Data Structures - 13
computer notes - Data Structures - 13computer notes - Data Structures - 13
computer notes - Data Structures - 13
 
Computer notes - Advanced Subqueries
Computer notes -   Advanced SubqueriesComputer notes -   Advanced Subqueries
Computer notes - Advanced Subqueries
 
Computer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group FunctionsComputer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group Functions
 
computer notes - Data Structures - 16
computer notes - Data Structures - 16computer notes - Data Structures - 16
computer notes - Data Structures - 16
 
computer notes - Data Structures - 22
computer notes - Data Structures - 22computer notes - Data Structures - 22
computer notes - Data Structures - 22
 
computer notes - Data Structures - 35
computer notes - Data Structures - 35computer notes - Data Structures - 35
computer notes - Data Structures - 35
 
computer notes - Data Structures - 36
computer notes - Data Structures - 36computer notes - Data Structures - 36
computer notes - Data Structures - 36
 
Computer notes - Enhancements to the GROUP BY Clause
Computer notes - Enhancements to the GROUP BY ClauseComputer notes - Enhancements to the GROUP BY Clause
Computer notes - Enhancements to the GROUP BY Clause
 
Computer notes - Manipulating Data
Computer notes - Manipulating DataComputer notes - Manipulating Data
Computer notes - Manipulating Data
 
Computer notes - Writing Basic SQL SELECT Statements
Computer notes - Writing Basic SQL SELECT StatementsComputer notes - Writing Basic SQL SELECT Statements
Computer notes - Writing Basic SQL SELECT Statements
 
computer notes - Data Structures - 14
computer notes - Data Structures - 14computer notes - Data Structures - 14
computer notes - Data Structures - 14
 

Último

Vector Methods.pptxjjjjjjjjjjjjjjjjjjjjjj
Vector Methods.pptxjjjjjjjjjjjjjjjjjjjjjjVector Methods.pptxjjjjjjjjjjjjjjjjjjjjjj
Vector Methods.pptxjjjjjjjjjjjjjjjjjjjjjj
joshuaclack73
 

Último (20)

Vip ℂall Girls Ansari Nagar Phone No 9999965857 High Profile ℂall Girl Delhi ...
Vip ℂall Girls Ansari Nagar Phone No 9999965857 High Profile ℂall Girl Delhi ...Vip ℂall Girls Ansari Nagar Phone No 9999965857 High Profile ℂall Girl Delhi ...
Vip ℂall Girls Ansari Nagar Phone No 9999965857 High Profile ℂall Girl Delhi ...
 
plantillas-powerpoint-hello-kitty.pptx.n
plantillas-powerpoint-hello-kitty.pptx.nplantillas-powerpoint-hello-kitty.pptx.n
plantillas-powerpoint-hello-kitty.pptx.n
 
Vip ℂall Girls Ghonda Phone No 9999965857 High Profile ℂall Girl Delhi No Adv...
Vip ℂall Girls Ghonda Phone No 9999965857 High Profile ℂall Girl Delhi No Adv...Vip ℂall Girls Ghonda Phone No 9999965857 High Profile ℂall Girl Delhi No Adv...
Vip ℂall Girls Ghonda Phone No 9999965857 High Profile ℂall Girl Delhi No Adv...
 
Vip ℂall Girls Mayapuri Phone No 9999965857 High Profile ℂall Girl Delhi No A...
Vip ℂall Girls Mayapuri Phone No 9999965857 High Profile ℂall Girl Delhi No A...Vip ℂall Girls Mayapuri Phone No 9999965857 High Profile ℂall Girl Delhi No A...
Vip ℂall Girls Mayapuri Phone No 9999965857 High Profile ℂall Girl Delhi No A...
 
Online Winbuzz ID Provider in India | Get Your Sports ID
Online Winbuzz ID Provider in India | Get Your Sports IDOnline Winbuzz ID Provider in India | Get Your Sports ID
Online Winbuzz ID Provider in India | Get Your Sports ID
 
ℂall Girls Krishna Nagar ℂall Now Chhaya ☎ 9899900591 WhatsApp Number 24/7
ℂall Girls Krishna Nagar ℂall Now Chhaya ☎ 9899900591 WhatsApp  Number 24/7ℂall Girls Krishna Nagar ℂall Now Chhaya ☎ 9899900591 WhatsApp  Number 24/7
ℂall Girls Krishna Nagar ℂall Now Chhaya ☎ 9899900591 WhatsApp Number 24/7
 
Vector Methods.pptxjjjjjjjjjjjjjjjjjjjjjj
Vector Methods.pptxjjjjjjjjjjjjjjjjjjjjjjVector Methods.pptxjjjjjjjjjjjjjjjjjjjjjj
Vector Methods.pptxjjjjjjjjjjjjjjjjjjjjjj
 
the red riding girl story fkjgoifdjgijogifdoin
the red riding girl story fkjgoifdjgijogifdointhe red riding girl story fkjgoifdjgijogifdoin
the red riding girl story fkjgoifdjgijogifdoin
 
The Gaming Quiz - 17th April 2024, Quiz Club NITW
The Gaming Quiz - 17th April 2024,  Quiz Club NITWThe Gaming Quiz - 17th April 2024,  Quiz Club NITW
The Gaming Quiz - 17th April 2024, Quiz Club NITW
 
Khaki-Files-Inside-Stories-of-Police-Missions-Kumar-Neeraj-Z-Library.pdf
Khaki-Files-Inside-Stories-of-Police-Missions-Kumar-Neeraj-Z-Library.pdfKhaki-Files-Inside-Stories-of-Police-Missions-Kumar-Neeraj-Z-Library.pdf
Khaki-Files-Inside-Stories-of-Police-Missions-Kumar-Neeraj-Z-Library.pdf
 
Get the Best Online Lotus ID from the Top Betting ID Provider.
Get the Best Online Lotus ID from the Top Betting ID Provider.Get the Best Online Lotus ID from the Top Betting ID Provider.
Get the Best Online Lotus ID from the Top Betting ID Provider.
 
ℂall Girls Chandni Chowk ℂall Now Chhaya ☎ 9899900591 WhatsApp Number 24/7
ℂall Girls Chandni Chowk ℂall Now Chhaya ☎ 9899900591 WhatsApp  Number 24/7ℂall Girls Chandni Chowk ℂall Now Chhaya ☎ 9899900591 WhatsApp  Number 24/7
ℂall Girls Chandni Chowk ℂall Now Chhaya ☎ 9899900591 WhatsApp Number 24/7
 
Vip ℂall Girls Noida Seℂtor 10 Phone No 9999965857 High Profile ℂall Girl Del...
Vip ℂall Girls Noida Seℂtor 10 Phone No 9999965857 High Profile ℂall Girl Del...Vip ℂall Girls Noida Seℂtor 10 Phone No 9999965857 High Profile ℂall Girl Del...
Vip ℂall Girls Noida Seℂtor 10 Phone No 9999965857 High Profile ℂall Girl Del...
 
Vip ℂall Girls Pasℂhim Puri Phone No 9999965857 High Profile ℂall Girl Delhi ...
Vip ℂall Girls Pasℂhim Puri Phone No 9999965857 High Profile ℂall Girl Delhi ...Vip ℂall Girls Pasℂhim Puri Phone No 9999965857 High Profile ℂall Girl Delhi ...
Vip ℂall Girls Pasℂhim Puri Phone No 9999965857 High Profile ℂall Girl Delhi ...
 
Vip ℂall Girls Mandi House Phone No 9999965857 High Profile ℂall Girl Delhi N...
Vip ℂall Girls Mandi House Phone No 9999965857 High Profile ℂall Girl Delhi N...Vip ℂall Girls Mandi House Phone No 9999965857 High Profile ℂall Girl Delhi N...
Vip ℂall Girls Mandi House Phone No 9999965857 High Profile ℂall Girl Delhi N...
 
PPT aviator (A small guide on spinmatch).pptx
PPT aviator (A small guide on spinmatch).pptxPPT aviator (A small guide on spinmatch).pptx
PPT aviator (A small guide on spinmatch).pptx
 
Vip ℂall Girls Jasola Vihar Phone No 9999965857 High Profile ℂall Girl Delhi ...
Vip ℂall Girls Jasola Vihar Phone No 9999965857 High Profile ℂall Girl Delhi ...Vip ℂall Girls Jasola Vihar Phone No 9999965857 High Profile ℂall Girl Delhi ...
Vip ℂall Girls Jasola Vihar Phone No 9999965857 High Profile ℂall Girl Delhi ...
 
Vip ℂall Girls Old Rajinder Nagar Phone No 9999965857 High Profile ℂall Girl ...
Vip ℂall Girls Old Rajinder Nagar Phone No 9999965857 High Profile ℂall Girl ...Vip ℂall Girls Old Rajinder Nagar Phone No 9999965857 High Profile ℂall Girl ...
Vip ℂall Girls Old Rajinder Nagar Phone No 9999965857 High Profile ℂall Girl ...
 
kiff2
kiff2kiff2
kiff2
 
Vip ℂall Girls Madhu Vihar Phone No 9999965857 High Profile ℂall Girl Delhi N...
Vip ℂall Girls Madhu Vihar Phone No 9999965857 High Profile ℂall Girl Delhi N...Vip ℂall Girls Madhu Vihar Phone No 9999965857 High Profile ℂall Girl Delhi N...
Vip ℂall Girls Madhu Vihar Phone No 9999965857 High Profile ℂall Girl Delhi N...
 

e computer notes - Hierarchical retrieval

  • 1. Hierarchical Retrieval http://ecomputernotes.com
  • 2. Objectives After completing this lesson, you should be able to do the following: " Interpret the concept of a hierarchical query " Create a tree-structured report " Format hierarchical data " Exclude branches from the tree structure http://ecomputernotes.com
  • 3. Sample Data from the EMPLOYEES Table http://ecomputernotes.com
  • 4. Natural Tree Structure EMPLOYEE_ID = 100 (Parent) King MANAGER_ID = 100 (Child) Mourgos Kochhar De Hann Hartstei Zlotkey alen Higgins Hunold Rajs Davies Matos Vargas Fay Abel Taylor Grant Gietz Ernst Lorentz http://ecomputernotes.com
  • 5. Hierarchical Queries SELECT [LEVEL], column , expr ... FROM table [WHERE condition(s) ] [START WITH condition(s) ] [CONNECT BY PRIOR condition(s) ] ; WHERE condition : expr comparison_operator expr http://ecomputernotes.com
  • 6. Walking the Tree Starting Point " Specifies the condition that must be met " Accepts any valid condition START WITH column1 = value Using the EMPLOYEES table, start with the employee whose last name is Kochhar. ...START WITH last_name = 'Kochhar' http://ecomputernotes.com
  • 7. Walking the Tree CONNECT BY PRIOR column1= column2 Walk from the top down, using the EMPLOYEES table. ... CONNECT BY PRIOR employee_id = manager_id Direction Top down Column1 = Parent Key Column2 = Child Key Bottom up Column1 = Child Key Column2 = Parent Key http://ecomputernotes.com
  • 8. Walking the Tree: From the Bottom Up SELECT employee_id, last_name, job_id, manager_id FROM employees START WITH employee_id = 101 CONNECT BY PRIOR manager_id = employee_id ; http://ecomputernotes.com
  • 9. Walking the Tree: From the Top Down SELECT last_name||' reports to '|| PRIOR last_name "Walk Top Down" FROM employees START WITH last_name = 'King' CONNECT BY PRIOR employee_id = manager_id ; « http://ecomputernotes.com
  • 10. Ranking Rows with the LEVEL Pseudocolumn Level 1 root/parent King Level 2 parent/child Mourgos chhar De Hann Hartstein Zlotkey Level 3 parent/ch en Higgins Hunold /leaf Rajs Davies Matos Vargas Fay Abel Taylor Grant Level 4 Gietz Ernst Lorentz leaf http://ecomputernotes.com
  • 11. Formatting Hierarchical Reports Using LEVEL and LPAD Create a report displaying company management levels, beginning with the highest level and indenting each of the following levels. OLUMN org_chart FORMAT A12 ELECT LPAD(last_name, LENGTH(last_name)+(LEVEL*2)-2,'_') AS org_chart ROM employees TART WITH last_name='King' ONNECT BY PRIOR employee_id=manager_id http://ecomputernotes.com
  • 12. Pruning Branches Use the WHERE clause Use the CONNECT BY clause to eliminate a node. to eliminate a branch. HERE last_name != 'Higgins' CONNECT BY PRIOR employee_id = manager_id AND last_name != 'Higgins' Kochhar Kochhar Whalen Higgins Whalen Higgins Gietz Gietz http://ecomputernotes.com