drop procedure top_salary / create or replace procedure top_salary(N IN Integer ) IS Cursor emp_cur(sal_in NUMBER) IS Select emp.name , emp.sal from EMP where sal = sal_in ; v_name emp.name%TYPE ; v_sal emp.sal%TYPE; i integer ; distinct_sal number; invalid_input Exception ; Begin select count(distinct(sal)) into distinct_sal from emp ; if (n < 0) or ( n=0) or (n > distinct_sal) then raise invalid_input ; end if ; select max(sal) into v_sal from emp ; for i in 1..N Loop open emp_cur(v_sal) ; Fetch emp_cur into v_name ,v_sal ; select name , sal into v_name,v_sal from emp where sal = v_sal and rownum = 1 ; DBMS_OUTPUT.PUT_LINE(v_name || ' ' || v_sal); close emp_cur ; select max(sal) into v_sal from emp where sal < v_sal ; end loop ; EXCEPTION when invalid_input then dbms_output.put_line( '============== Invalid Input ============='); end; / Accept num prompt 'ENter Integer N : ' declare n integer := &num ; begin top_salary(n); end; /