GTU MCA MATERIAL FOR DBMS II

RSS
  • Home
  • Quick Review
  • Assignment
  • Backup and Recovery
  • Differences
  • About Me

Wednesday, August 10, 2016

SQL query for hierarchical retrieval of employees working in any organization.

To evaluates hierarchical query oracle provides PRIOR expression of CONNECT BY condition.

Example



CREATE TABLE employees 
  ( 
     empid       INT PRIMARY KEY, 
     ename       VARCHAR2(30) NOT NULL, 
     designation VARCHAR2(20), 
     parent_id   INT 
  );


SELECT * FROM EMPLOYEES;

     EMPID ENAME                          DESIGNATION           PARENT_ID
---------- ------------------------------ -------------------- ----------
         1 P.P.TYAG VALLABH SWAMIJI       SECRETARY
         2 Dr.J.N.Shah                    DIRECTOR                      1
         3 Dr.G.D.Acharya                 PRINCIPAL                     2
         4 Dr.S.R.VARMA                   PRINCIPAL                     2
         5 Dr.K.R.VADALIYA                PRINCIPAL                     2
         6 Dr.G.C.JOSHI                   PRINCIPAL                     2
         7 Dr.A.U.PATEL                   PRINCIPAL                     2
         8 Dr.NISHANT VACHHANI            HOD                           4
         9 Dr.ASHISH KOTHARI              HOD                           3
        10 PROF.J.N.RATHOD                HOD                           3
        11 PROF.P.C.SHUKLA                HOD                           4
        12 DR.STAVAN PATEL                HOD                           7
        13 PROF.ANKIT FALDU               ASSISTANT PROFESSOR          11
        14 DR.PRATIK VANZARA              ASSISTANT PROFESSOR          12
        15 PROF.VIVEK VYAS                ASSISTANT PROFESSOR          11
        16 PROF.KALPESH POPAT             ASSISTANT PROFESSOR          11
        17 PROF.PRAKASH GUJARATI          ASSISTANT PROFESSOR          12
        18 PROF.DIVYESH GOHEL             ASSISTANT PROFESSOR          12
        19 DR.AMIT RAJDEV                 ASSISTANT PROFESSOR           8
        20 PROF.ANKIT GANDHI              ASSISTANT PROFESSOR           8


20 rows selected.


SELECT Sys_connect_by_path(ename, '-') "Path" 
FROM   employees 
START WITH Upper(ename) = 'P.P.TYAG VALLABH SWAMIJI' 
CONNECT BY PRIOR empid = parent_id 


SELECT ename, designation, LEVEL 
FROM   employees 
START WITH Upper(ename) = 'P.P.TYAG VALLABH SWAMIJI' 
CONNECT BY PRIOR empid = parent_id 











Posted by Dr. Parag Shukla at 9:02:00 AM
Email This BlogThis! Share to X Share to Facebook
Labels: Employee Level, Hierarchical, Level, SQL Query

0 comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Total Pageviews

255045

Blog Archive

  • ►  2019 (1)
    • ►  March (1)
  • ▼  2016 (7)
    • ▼  August (6)
      • Difference Between System Level Privileges and Obj...
      • SQL Query to recover dropped tables.
      • SQL query for hierarchical retrieval of employees ...
      • How to Delete duplicate email_ids from table using...
      • SQL Query to perform result analysis of the subjects
      • SQL Query for Grade Calculations
    • ►  July (1)
  • ►  2011 (16)
    • ►  May (2)
    • ►  April (6)
    • ►  March (5)
    • ►  February (3)
  • ►  2010 (9)
    • ►  May (4)
    • ►  March (5)
  • ►  2009 (1)
    • ►  December (1)

Followers

Blog List

Search

Parag Shukla. Powered by Blogger.

Popular Posts

  • Serial Schedule Vs Non-Serial Schedule
    Serial Schedule Non-Serial Schedule A serial schedule is a sequence of operat...
  • Dirty Read Vs Unrepeatable Read
    Dirty Read Unrepeatable Read A dirty read problem occurs when one transaction updates a ...
  • Log Based Recovery
    Log Based Recovery The most widely used structure for recording database modification is the log. The log is a sequence of log ...
  • Lost Update Vs Uncommitted Data
    Lost Update Uncommitted Data This problem is also known as “Multiple Update...
  • Shadow Paging
    Shadow Paging This technique does not require LOG in single user environment In mult...
  • Starvation Vs Deadlock
    Starvation Deadlock Starvation happens if same transaction is always choosen ...
  • Checkpoints
    Checkpoints When System failure occurs o We must consult log to determine those transaction that need to be redone and those tra...
  • Defferred Update method
    Deferred update Do not physically update the database on disk until after a transaction reaches its commit point; Then updates are r...
  • Assignment - 7 Query Processing & Optimization
    Assignment – 7         Query Processing & optimization    Submission Date 30-05-11   Q-1. Explain th...
  • Immediate Update Method
    Immediate update technique Database may be updated by some operations of a transaction before the transaction reaches its commit poi...
Copyright © 2010 GTU MCA MATERIAL FOR DBMS II