fetch bulk collect into 的使用格式是:fetch some_cursor collect into col1, col2 limit xxx。col1、col2 是声明的集合类型变量,xxx 为每次取数据块的大小(记录数),相当于缓冲区的大小,可以不指定 limit xxx 大小。下面以实际的例子来说明它的使用,并与逐条取记录的 fetch into 执行效率上进行比较。
使用 fetch bulk collect into 获取游标数据
01.
declare
02.
03.
--声明需要集合类型及变量,参照字段的 type 来声明类型
04.
type id_type
is
table
of
sr_contacts.sr_contact_id%type;
05.
v_id id_type;
06.
07.
type phone_type
is
table
of
sr_contacts.contact_phone%type;
08.
v_phone phone_type;
09.
10.
type remark_type
is
table
of
sr_contacts.remark%type;
11.
v_remark remark_type;
12.
13.
cursor
all_contacts_cur
is
--用 rownum 来限定取出的记录数来测试
14.
select
sr_contact_id,contact_phone,remark
from
sr_contacts
where
rownum <= 100000;
15.
16.
begin
17.
18.
open
all_contacts_cur;
19.