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 >> pla help me.

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: pla help me.
 Garlapati  Posted: Feb 29, 2008 03:37:53 AM

 Total Post: 30
 Joined: Apr, 2007






 i want to diaply the top6 salaries in each department
pla help me.
thanq advance

 pammi
Posted: Feb 29, 2008 04:20:55 AM  

 Total Post: 21
 Joined: Feb, 2008






 
I have the solution in pl/sql. Just go thru it.


declare
cursor c1 is select deptno from dept;
c2 c1%rowtype;
cursor c3(dno number) is
select rownum,sal from(select distinct sal ,deptno from emp where sal is not null order by sal desc ) where rownum<=6
and deptno=dno;
c4 c3%rowtype;
begin
open c1;
loop
fetch c1 into c2;
exit when c1%notfound;
dbms_output.put_line(c2.deptno);
for c4 in c3(c2.deptno) loop
dbms_output.put_line( c4.rownum|| ' ' ||c4.sal);
end loop;
end loop;
close c1;
end;
/


 Murtuja
Posted: Feb 29, 2008 04:27:27 AM  

 Total Post: 857
 Joined: Jan, 2006






 
Hi ,

SELECT * FROM (
SELECT deptno, ename, sal,
DENSE_RANK()
OVER (
PARTITION BY deptno ORDER BY sal desc
) TopN FROM emp
)
WHERE TopN <= 6
ORDER BY deptno, sal DESC



 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 Kaushik387
  Vinoth Kumar379
  Gopu Gopi350
  Gitesh Trivedi322
  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