DECLARE
CURSOR EMPCUR
SELECT EMPNO,ENAME,SAL,ROWNUM
FROM (SELECT *
FROM EMP
ORDER BY SAL DESC)
WHERE ROWNUM<=3
ORDER BY ROWNUM;
BEGIN
FOR EMPREC IN EMPCUR
LOOP
DBMS_OUTPUT.PUT_LINE('RANK '||EMPREC.ROWNUM);
DBMS_OUTPUT.PUT_LINE(EMPREC.EMONO||' - '||EMPREC.ENAME||' - '||EMPREC.SAL);
END LOOP;
END;
/
This code does not work:
ERROR at line 2: ORA-06550: line 2, column 17: PLS-00103: Encountered the symbol "SELECT" when expecting one of the following: ( ; is return The symbol "is" was substituted for "SELECT" to continue.
IS
keyword missed in theEMPCUR
cursor declaration. Moreover, there is really no need to useORDER BY ROWNUM
in this particular situation. – Nick Krasnov