June 14, 2011

skip a record in a cursor and continue with the next record in oracle

To skip a record in a cursor and continue with the next record you can try below code in oracle or sql.



 declare  
 cursor cur1 is select * from emp;  
 rec cur1%rowtype;  
 begin  
 open cur1;  
 loop  
 fetch cur1 into rec;  
 dbms_output.put_line(rec.ename||' '||rec.sal);  
 fetch cur1 into rec;  
 exit when cur1%notfound;  
 end loop;  
 close cur1;  
 end;