Home » SQL & PL/SQL » SQL & PL/SQL » Question on EXIT WHEN statement
Question on EXIT WHEN statement [message #1542] Fri, 10 May 2002 12:24 Go to next message
Srini
Messages: 28
Registered: November 2000
Junior Member
Inside a for loop (which is a cursor), if i use EXIT WHEN <some condition>, will it automatically close the cursor of the for loop when it comes out of the loop ?

Thanks.
Re: Question on EXIT WHEN statement [message #1555 is a reply to message #1542] Sun, 12 May 2002 10:15 Go to previous messageGo to next message
shaheena
Messages: 17
Registered: February 2002
Junior Member
hello srini,
for loop implicitly open,fetch and closes the cursor but it is recommended that do not use for loop if you want to handle cursor operations manually you can use any other loop for this purpose.
regards.
shaheena.
Re: Question on EXIT WHEN statement [message #1557 is a reply to message #1542] Mon, 13 May 2002 00:44 Go to previous messageGo to next message
John R
Messages: 156
Registered: March 2000
Senior Member
If you use a cursor for loop ie:

FOR rec IN c_cursor LOOP
....
....
END LOOP;

Then exiting the loop will close the cursor.

If you use a manual loop, ie

OPEN c_cursor;
LOOP
__FETCH c_cursor INTO l_record;
__EXIT WHEN c_cursor%NOTFOUND;
END LOOP;

Then you need to close the cursor explictly.
Re: Question on EXIT WHEN statement [message #1561 is a reply to message #1542] Mon, 13 May 2002 05:38 Go to previous message
Srini
Messages: 28
Registered: November 2000
Junior Member
Thanks Shaheena, It was really helpful. Also thanks John.
Previous Topic: Tune a sql statement with 5 joint tables
Next Topic: how to delete specific number of records in a table
Goto Forum:
  


Current Time: Mon May 20 12:47:38 CDT 2024