SlideShare uma empresa 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

Mais conteúdo relacionado

Mais 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
 

Mais 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

Low Rate Young Call Girls in Surajpur Greater Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Surajpur Greater Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Surajpur Greater Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Surajpur Greater Noida ✔️☆9289244007✔️☆ Female E...
SofiyaSharma5
 
Call Girls Chirag Delhi Delhi WhatsApp Number 9711199171
Call Girls Chirag Delhi Delhi WhatsApp Number 9711199171Call Girls Chirag Delhi Delhi WhatsApp Number 9711199171
Call Girls Chirag Delhi Delhi WhatsApp Number 9711199171
Delhi Call Girls 📞9899900591 ✔️ High Profile Service 100% Safe
 
Call Girls In Goa 9316020077 Goa Call Girl By Indian Call Girls Goa
Call Girls In Goa  9316020077 Goa  Call Girl By Indian Call Girls GoaCall Girls In Goa  9316020077 Goa  Call Girl By Indian Call Girls Goa
Call Girls In Goa 9316020077 Goa Call Girl By Indian Call Girls Goa
sexy call girls service in goa
 
CHEAP Call Girls in Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in  Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in  Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call Girls Agency In Goa 💚 9316020077 💚 Call Girl Goa By Russian Call Girl ...
Call Girls  Agency In Goa  💚 9316020077 💚 Call Girl Goa By Russian Call Girl ...Call Girls  Agency In Goa  💚 9316020077 💚 Call Girl Goa By Russian Call Girl ...
Call Girls Agency In Goa 💚 9316020077 💚 Call Girl Goa By Russian Call Girl ...
russian goa call girl and escorts service
 
Russian Escorts Agency In Goa 💚 9316020077 💚 Russian Call Girl Goa
Russian Escorts Agency In Goa  💚 9316020077 💚 Russian Call Girl GoaRussian Escorts Agency In Goa  💚 9316020077 💚 Russian Call Girl Goa
Russian Escorts Agency In Goa 💚 9316020077 💚 Russian Call Girl Goa
sexy call girls service in goa
 
Karnal Call Girls 8860008073 Dyal Singh Colony Call Girls Service in Karnal E...
Karnal Call Girls 8860008073 Dyal Singh Colony Call Girls Service in Karnal E...Karnal Call Girls 8860008073 Dyal Singh Colony Call Girls Service in Karnal E...
Karnal Call Girls 8860008073 Dyal Singh Colony Call Girls Service in Karnal E...
Apsara Of India
 

Último (20)

↑Top Model (Kolkata) Call Girls Salt Lake ⟟ 8250192130 ⟟ High Class Call Girl...
↑Top Model (Kolkata) Call Girls Salt Lake ⟟ 8250192130 ⟟ High Class Call Girl...↑Top Model (Kolkata) Call Girls Salt Lake ⟟ 8250192130 ⟟ High Class Call Girl...
↑Top Model (Kolkata) Call Girls Salt Lake ⟟ 8250192130 ⟟ High Class Call Girl...
 
Low Rate Young Call Girls in Surajpur Greater Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Surajpur Greater Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Surajpur Greater Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Surajpur Greater Noida ✔️☆9289244007✔️☆ Female E...
 
Independent Joka Escorts ✔ 8250192130 ✔ Full Night With Room Online Booking 2...
Independent Joka Escorts ✔ 8250192130 ✔ Full Night With Room Online Booking 2...Independent Joka Escorts ✔ 8250192130 ✔ Full Night With Room Online Booking 2...
Independent Joka Escorts ✔ 8250192130 ✔ Full Night With Room Online Booking 2...
 
Call Girl Nashik Saloni 7001305949 Independent Escort Service Nashik
Call Girl Nashik Saloni 7001305949 Independent Escort Service NashikCall Girl Nashik Saloni 7001305949 Independent Escort Service Nashik
Call Girl Nashik Saloni 7001305949 Independent Escort Service Nashik
 
Call Girls Chirag Delhi Delhi WhatsApp Number 9711199171
Call Girls Chirag Delhi Delhi WhatsApp Number 9711199171Call Girls Chirag Delhi Delhi WhatsApp Number 9711199171
Call Girls Chirag Delhi Delhi WhatsApp Number 9711199171
 
Call Girls In Goa 9316020077 Goa Call Girl By Indian Call Girls Goa
Call Girls In Goa  9316020077 Goa  Call Girl By Indian Call Girls GoaCall Girls In Goa  9316020077 Goa  Call Girl By Indian Call Girls Goa
Call Girls In Goa 9316020077 Goa Call Girl By Indian Call Girls Goa
 
5* Hotels Call Girls In Goa {{07028418221}} Call Girls In North Goa Escort Se...
5* Hotels Call Girls In Goa {{07028418221}} Call Girls In North Goa Escort Se...5* Hotels Call Girls In Goa {{07028418221}} Call Girls In North Goa Escort Se...
5* Hotels Call Girls In Goa {{07028418221}} Call Girls In North Goa Escort Se...
 
Model Call Girls In Velappanchavadi WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Velappanchavadi WhatsApp Booking 7427069034 call girl ser...Model Call Girls In Velappanchavadi WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Velappanchavadi WhatsApp Booking 7427069034 call girl ser...
 
𓀤Call On 6297143586 𓀤 Sonagachi Call Girls In All Kolkata 24/7 Provide Call W...
𓀤Call On 6297143586 𓀤 Sonagachi Call Girls In All Kolkata 24/7 Provide Call W...𓀤Call On 6297143586 𓀤 Sonagachi Call Girls In All Kolkata 24/7 Provide Call W...
𓀤Call On 6297143586 𓀤 Sonagachi Call Girls In All Kolkata 24/7 Provide Call W...
 
Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...
 
↑Top Model (Kolkata) Call Girls Howrah ⟟ 8250192130 ⟟ High Class Call Girl In...
↑Top Model (Kolkata) Call Girls Howrah ⟟ 8250192130 ⟟ High Class Call Girl In...↑Top Model (Kolkata) Call Girls Howrah ⟟ 8250192130 ⟟ High Class Call Girl In...
↑Top Model (Kolkata) Call Girls Howrah ⟟ 8250192130 ⟟ High Class Call Girl In...
 
👙 Kolkata Call Girls Shyam Bazar 💫💫7001035870 Model escorts Service
👙  Kolkata Call Girls Shyam Bazar 💫💫7001035870 Model escorts Service👙  Kolkata Call Girls Shyam Bazar 💫💫7001035870 Model escorts Service
👙 Kolkata Call Girls Shyam Bazar 💫💫7001035870 Model escorts Service
 
CHEAP Call Girls in Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in  Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in  Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Book Sex Workers Available Kolkata Call Girls Service Airport Kolkata ✔ 62971...
Book Sex Workers Available Kolkata Call Girls Service Airport Kolkata ✔ 62971...Book Sex Workers Available Kolkata Call Girls Service Airport Kolkata ✔ 62971...
Book Sex Workers Available Kolkata Call Girls Service Airport Kolkata ✔ 62971...
 
Call Girls in Barasat | 7001035870 At Low Cost Cash Payment Booking
Call Girls in Barasat | 7001035870 At Low Cost Cash Payment BookingCall Girls in Barasat | 7001035870 At Low Cost Cash Payment Booking
Call Girls in Barasat | 7001035870 At Low Cost Cash Payment Booking
 
Call Girls Agency In Goa 💚 9316020077 💚 Call Girl Goa By Russian Call Girl ...
Call Girls  Agency In Goa  💚 9316020077 💚 Call Girl Goa By Russian Call Girl ...Call Girls  Agency In Goa  💚 9316020077 💚 Call Girl Goa By Russian Call Girl ...
Call Girls Agency In Goa 💚 9316020077 💚 Call Girl Goa By Russian Call Girl ...
 
2k Shot Call girls Laxmi Nagar Delhi 9205541914
2k Shot Call girls Laxmi Nagar Delhi 92055419142k Shot Call girls Laxmi Nagar Delhi 9205541914
2k Shot Call girls Laxmi Nagar Delhi 9205541914
 
👙 Kolkata Call Girls Sonagachi 💫💫7001035870 Model escorts Service
👙  Kolkata Call Girls Sonagachi 💫💫7001035870 Model escorts Service👙  Kolkata Call Girls Sonagachi 💫💫7001035870 Model escorts Service
👙 Kolkata Call Girls Sonagachi 💫💫7001035870 Model escorts Service
 
Russian Escorts Agency In Goa 💚 9316020077 💚 Russian Call Girl Goa
Russian Escorts Agency In Goa  💚 9316020077 💚 Russian Call Girl GoaRussian Escorts Agency In Goa  💚 9316020077 💚 Russian Call Girl Goa
Russian Escorts Agency In Goa 💚 9316020077 💚 Russian Call Girl Goa
 
Karnal Call Girls 8860008073 Dyal Singh Colony Call Girls Service in Karnal E...
Karnal Call Girls 8860008073 Dyal Singh Colony Call Girls Service in Karnal E...Karnal Call Girls 8860008073 Dyal Singh Colony Call Girls Service in Karnal E...
Karnal Call Girls 8860008073 Dyal Singh Colony Call Girls Service in Karnal E...
 

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