The traditional fetch into only one data at a time, using the fetch bulk collect into can get all the data from the cursor at once, use the limit clause to limit the number of data bars taken at a time
1, fetch bulk collect into
Begin
Declare
cursor c_dept is select * from dept;
Type Dept_record is table of Dept%rowtype;
V_dept Dept_record;
Begin
Open c_dept;
Fetch c_dept bulk collect into v_dept;
Close c_dept;
For I in 1. V_dept.count Loop
dbms_output.put_line (' Department Name: ' | | V_dept (i). dname| | ' Department Address: ' | | V_dept (i). Loc);
End Loop;
End;
End
2, using the limit clause to limit the number of rows fetched
Begin
Declare
cursor c_dept is select * from dept;
Type Dept_record is table of Dept%rowtype;
V_dept Dept_record;
Begin
Open c_dept;
Loop
exit when C_dept%notfound;
Fetch c_dept Bulk collect into v_dept limit 3;
Dbms_output.put_line ('-----------------------------------------------------------');
For I in 1. V_dept.count Loop
dbms_output.put_line (' Department Name: ' | | V_dept (i). dname| | ' Department Address: ' | | V_dept (i). Loc);
End Loop;
End Loop;
Close c_dept;
End;
End