If the fetch statement is not executed once before the while loop the while condition will return false in the first instance and the while loop is skipped.
In the loop, before fetching the record again, always process the record retrieved by the first fetch statement, else you will skip the first row.
Second, we are declaring a cursor ‘emp_cur’ from a select query in line no 3 - 6.
Oracle provides three types of cursors namely SIMPLE LOOP, WHILE LOOP and FOR LOOP.General Form of using an explicit cursor is: In the above example, first we are creating a record ‘emp_rec’ of the same structure as of table ‘emp_tbl’ in line no 2.We can also create a record with a cursor by replacing the table name with the cursor name.· If you are fetching a cursor to a PL/SQL Record, the record should have the same structure as the cursor.· If you are fetching a cursor to a list of variables, the variables should be listed in the same order in the fetch statement as the columns are present in the cursor.We can use %FOUND in place of %NOTFOUND and vice versa. In the above example, in line no 10 we are using %FOUND to evaluate if the first fetch statement in line no 9 returned a row, if true the program moves into the while loop.