PL/SQL Cursor to Display Last Five Records

PL/SQL Cursor to Display Last Five Records:


declare
tot number;
cnt number;
rcnt number;
cursor last_five_record is select * from emp;
begin
cnt:=1;
select count(*) into tot from emp;
rcnt:=tot-5;
for i in last_five_record
loop
if(cnt>rcnt)then
dbms_output.put_line(i.empno||' '||i.ename||' '||i.job||' '||i.sal);
end if;
cnt:=cnt+1;
end loop;
end;

OUTPUT:

7654 MARTIN SALESMAN 1250
7844 TURNER SALESMAN 1500
7876 ADAMS CLERK 1100
7900 JAMES CLERK 950
7934 MILLER CLERK 1300



Leave a Reply

Your email address will not be published. Required fields are marked *

two − 1 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.