PL/SQL Cursor to Display Records in Even Numbers

PL/SQL Cursor to Display Records in Even Numbers:

declare
cursor s_even is select * from student;
cnt number;
rcnt number;
begin
cnt:=2;
rcnt:=1;
for i in s_even
loop
if(cnt = rcnt) then
dbms_output.put_line(i.id||' '||i.name||' '||i.salary);
cnt:=cnt+2;
end if;
rcnt:=rcnt+1;
end loop;
end;

OUTPUT:

2 John 150000
4 Rahul 500000
6 Simi 100000

Leave a Reply

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

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