输入的数决定显示人数。EX:输入2,就显示最高的2人名字。
1.
create procedure
-
CREATE OR REPLACE PROCEDURE pro_emp (nu IN NUMBER) IS
-
CURSOR cur_emp IS SELECT ename FROM (SELECT ename,row_number()over(ORDER BY sal DESC) rn FROM emp) t WHERE t.rn<=nu;
-
BEGIN
-
FOR i IN cur_emp LOOP
-
dbms_output.put_line(i.ename);
-
END LOOP;
-
END;
2.test
-
Connected to Oracle Database 10g Enterprise Edition Release 10.1.0.2.0
-
Connected as yangkai
-
-
SQL> set serveroutput on;
-
SQL> exec pro_emp(2);
-
-
KING
-
SCOTT
-
-
PL/SQL procedure successfully completed
-
-
SQL>
阅读(1138) | 评论(0) | 转发(0) |