%NOTFOUND - Question on why the EXIT condition is placed right after FETCH
So i have a procedure that uses a cursor as well as a loop to output the values as follows
LOOP
/* Retrieve each row of the result of the above query into PL/SQL variables: */
FETCH AREA_CUR INTO P_ID, P_LAST_NAME, P_DEPTH;
/* If there are no more rows to fetch, exit the loop: */
EXIT WHEN AREA_CUR%NOTFOUND;
DBMS_OUTPUT.PUT_LINE('Student ID: '||P_ID);
DBMS_OUTPUT.PUT_LINE('Student Last Name: '||P_LAST_NAME);
DBMS_OUTPUT.PUT_LINE('Depth: '||P_DEPTH);
END LOOP;
Right now, if i were to run my procedure i would get output of
Schmidt
Burha
Which is expected
But i noticed if i were to switch the EXIT statement to the end just before the end loop i get slightly different results
LOOP
/* Retrieve each row of the result of the above query into PL/SQL variables: */
FETCH AREA_CUR INTO P_ID, P_LAST_NAME, P_DEPTH;
DBMS_OUTPUT.PUT_LINE('Student ID: '||P_ID);
DBMS_OUTPUT.PUT_LINE('Student Last Name: '||P_LAST_NAME);
DBMS_OUTPUT.PUT_LINE('Depth: '||P_DEPTH);
/* If there are no more rows to fetch, exit the loop: */
EXIT WHEN AREA_CUR%NOTFOUND;
END LOOP;
I then get the results of
Schmidt
Buhra
Burha
From what I understand after a FETCH statement is issued, it will take the current value of the row its in and then also move to the next line.
Why would it pick up Burha twice?
Since the FETCH statement moves to the next line i would expect the output to look more like
Schmidt
Buhra
<Blank> (as this would be the newest line)
Am i misunderstanding this?