Home » SQL & PL/SQL » SQL & PL/SQL » Closing the cursor
Closing the cursor [message #316750] Mon, 28 April 2008 04:00 Go to next message
xyzt
Messages: 27
Registered: April 2008
Junior Member
Hello,

In Oracle documentation, there's a sample for CURSORs as this:
DECLARE
my_sal emp.sal%TYPE;
my_job emp.job%TYPE;
factor INTEGER := 2;
CURSOR c1 IS SELECT factor*sal FROM emp WHERE job = my_job;
BEGIN
...
OPEN c1; -- here factor equals 2
LOOP
FETCH c1 INTO my_sal;
EXIT WHEN c1%NOTFOUND;
factor := factor + 1; -- does not affect FETCH
END LOOP;
END;


I wonder why the CURSOR c1 is not closed? Is a cursor is closed automatically if it came to the end? or there's a fault in the code?

Re: Closing the cursor [message #316756 is a reply to message #316750] Mon, 28 April 2008 04:16 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
It is an error, it should be closed.

Regards
Michel
Re: Closing the cursor [message #316757 is a reply to message #316756] Mon, 28 April 2008 04:19 Go to previous message
xyzt
Messages: 27
Registered: April 2008
Junior Member
Thanks very much.
Previous Topic: date time parameter
Next Topic: LOOP Insert record cursor from one table to another
Goto Forum:
  


Current Time: Sun Dec 04 08:54:28 CST 2016

Total time taken to generate the page: 0.04899 seconds