Examine the following PL/SQL code:
Which statement is true about the fetch statements in the PL/SQL code?
A. Each fetch retrieves the first row and assigns values to the target variables.
B. Each fetch retrieves the next consecutive row and assigns values to the target variables.
C. They produce an error because you must close and reopen the cursor before each fetch -statement.
D. Only the first fetch retrieves the first row and assigns values to the target variables- the second produces an error.
Also think correct answer is B.
Below code confirms it:
set serveroutput on;
declare
cursor c1 is select last_name from employees order by last_name;
name1 employees.last_name%type;
name2 employees.last_name%type;
name3 employees.last_name%type;
begin
open c1;
fetch c1 into name1;
dbms_output.put_line(‘name1 variable value is: ‘||name1);
fetch c1 into name2;
dbms_output.put_line(‘name2 variable value is: ‘||name2);
fetch c1 into name3;
dbms_output.put_line(‘name3 variable value is: ‘||name3);
close c1;
end;
/
name1 variable value is: Abel
name2 variable value is: Ande
name3 variable value is: Atkinson