Home » SQL & PL/SQL » SQL & PL/SQL » exit for a CURSOR FOR..LOOP
exit for a CURSOR FOR..LOOP [message #9983] Thu, 18 December 2003 19:27 Go to next message
resy
Messages: 86
Registered: December 2003
Member
How is the exit condition defined for a cursor for loop
Re: exit for a CURSOR FOR..LOOP [message #9988 is a reply to message #9983] Thu, 18 December 2003 23:32 Go to previous message
Barbara Boehmer
Messages: 9088
Registered: November 2002
Location: California, USA
Senior Member
The exit is implicit; It exits when it runs out of rows in the cursor. However, you can add an additional explicit exit. Please see the examples below.

scott@ORA92> set serveroutput on
scott@ORA92> -- without explicit exit:
scott@ORA92> begin
  2    for rec in (select * from dept order by deptno)
  3    loop
  4  	 dbms_output.put_line (rec.deptno);
  5    end loop;
  6  end;
  7  /
10
20
30
40

PL/SQL procedure successfully completed.

scott@ORA92> -- with explicit exit:
scott@ORA92> begin
  2    for rec in (select * from dept order by deptno)
  3    loop
  4  	 dbms_output.put_line (rec.deptno);
  5  	 exit when rec.deptno = 30;
  6    end loop;
  7  end;
  8  /
10
20
30

PL/SQL procedure successfully completed.
Previous Topic: need help , very important
Next Topic: help needed
Goto Forum:
  


Current Time: Thu Apr 18 18:50:57 CDT 2024