Oracle uses bulkcollect to implement SQL statements for batch fetch of cursor. You can try it with friend El.
Oracle uses bulk collect to implement SQL statements for batch fetch of cursor. You can try it with friend El.
In general, there are not many chances to use fetch in batches, but we 'd better get familiar with this feature provided by Oracle, and maybe it will be used at any time.
The Code is as follows:
Declare
Cursor c1 is select * from t_depart;
V_depart t_depart % rowtype;
Type v_code_type is table of t_0000.depart_code % type;
V_code v_code_type;
Type v_name_type is table of t_0000.depart_name % type;
V_name v_name_type;
Begin
Open c1;
Fetch c1 bulk collect into v_code, v_name;
For I in 1 .. v_code.count loop
Dbms_output.put_line (v_code (I) | ''| v_name (I ));
End loop;
Close c1;
End;
Through the above column, you can find that if there are many columns, defining a set for each column seems complicated. You can combine the set with % rowtype to use the simplified program!
The Code is as follows:
Declare
Cursor c1 is select * from t_depart;
Type v_depart_type is table of t_depart % rowtype;
V_depart v_depart_type;
Begin
Open c1;
Fetch c1 bulk collect into v_depart;
For I in 1 .. v_).count loop
Dbms_output.put_line (v_depart (I). depart_code | ''|
V_depart (I). depart_name );
End loop;
Close c1;
End;
When outputting results, you can use both the count attribute of the Set and the first and last attributes. When referencing content of the % rowtype, you must note that v_depart (I ). depart_code, rather than v_pai.depart_code (I), is of course not written in this way, even if it makes sense.
The Code is as follows:
Declare
Cursor c1 is select * from t_depart;
Type v_depart_type is table of t_depart % rowtype;
V_depart v_depart_type;
Begin
Open c1;
Fetch c1 bulk collect into v_depart;
For I in v_mongo.first... v_mongo.last loop
Dbms_output.put_line (v_depart (I). depart_code | ''|
V_depart (I). depart_name );
End loop;
Close c1;
End;