Job Seekers   Employers
dbapool: Authors | Submissions | Contact Us
   Forgot password? | Sign up
  Home   Discussion Forum   Articles   Interview Questions   FAQs   Scripts   Rewards   Analyzer   White Papers   Blog   Certification   Downloads   Tools
 

Topic: SQL*Plus and PL/SQL >> Query Required

Disclaimer: The purpose of all dbapool forums including OCP and Other Oracle Certification forums is to help each other with specific issues but not to share dump and copyrighted exam content, materials or intellectual property. You may review the entire Oracle Certification Program Candidate Agreement online Here.



  


 Title: Query Required
 Ramesh Joyisa  Posted: Oct 24, 2007 06:13:47 AM

 Total Post: 246
 Joined: Aug, 2007






 Can any body give a query to return hierarchical relation form the data of one table. Ex
SQL> desc test
Name Null? Type
----------------------------------------- -------- --------------
A NUMBER
B NUMBER

SQL> select * from test;

A B
---------- ----------
1 2
2 3
2 4
3 4
5 6

The output required is
1 2
2 3
2 4
3 4

 chinna
Posted: Oct 25, 2007 03:25:11 AM  

 Total Post: 28
 Joined: May, 2007






 
hi,
Thanks for such a good question.
Here is the Query:

SELECT LEVEL AS HierarchyLevel,NO1 ,NO2 FROM RM
CONNECT BY PRIOR NO2=NO1
START WITH NO1=1
ORDER BY LEVEL


STARTWITH Clause to specify the Start of the tree.
CONNECT BY PRIOR is the internal cursor.
LEVEL indicates the position in the hierarchal tree.

Thanks
Srawan


 Ramesh Joyisa
Posted: Oct 25, 2007 07:28:55 AM  

 Total Post: 246
 Joined: Aug, 2007






 
Good.. Thanks.. In Addition to the above question, the next question is how get the only related number. i.e if i give parameter as 1 then i want the list of all the numbers that are related to 1.out put is

Related
------
2
3
4




 chinna
Posted: Oct 25, 2007 07:36:23 AM  

 Total Post: 28
 Joined: May, 2007






 
hi,
It itself gives the answer if we slightly modify the query according to our requirement

SELECT DISTINCT NO2 FROM RM
CONNECT BY PRIOR NO2=NO1
START WITH NO1=2 /* The value depends on us.*/

ok
Take Care
Byee
Thanks
Srawan

 Time Zone: EDT

  




Forum Rules & Description


Who Can Read The Forum? Any registered user or guest
Who Can Post New Topics? Any registered user
Who Can Post Replies? Any registered user




 








Get FREE Magazines

Top 10 Forum User

  Murtuja Khokhar857
  Mohammed Taj746
  positive fanatic483
  Jayanta Sur479
  Vigyan Kaushik386
  Gopu Gopi327
  Gitesh Trivedi322
  Vinoth Kumar264
  neeraj sharma258
  Ramesh Jois246






oracle Mag



  About Us Advertise Terms of Use Privacy Newsletters Contact Us    

Home   Discussion Forum   FAQs  Articles  Jobs   Newsletters  Directory  Downloads 

Our Premium Sponsor
Confio Software