查询工资排名前三的员工姓名和工资(sql和plsql两种方法实现)

select ename,sal from emp where 
   empno in (select empno from (select empno,sal from emp order by sal desc )t
   where rownum<4);

 

declare 
  v_name varchar2(10);
  v_sal number(5);
  cursor emp_cursor is select ename,sal from emp order by sal desc;
  begin 
  open emp_cursor;
  for i in 1..3
  loop
  fetch emp_cursor into v_name,v_sal;
  dbms_output.put_line(v_name||','||v_sal);
  end loop;
  close emp_cursor;
  end;

 

你可能感兴趣的:(Oracle)