天天看點

bulk collect into之limit的使用

BULK COLLECT

可以降低 SQL 引擎到 PL/SQL 引擎的上下文交換(context switch)次數,,進而實作資料的高速檢索。”并不是限制必須一次完成。Oracle

提供了 LIMIT 子句,可以限制每次從表中擷取的記錄數,測試如下:

SQL> select count(*) from t;

  COUNT(*)

----------

536

SQL> declare

  2    cursor c_t is select * from

t;

  3    type typ_t is table of

c_t%rowtype

  4    index by

binary_integer; 

  5    v_type_t

typ_t;

  6    v_row

pls_integer;

  7  begin

  8    open

c_t;

  9    loop

10    fetch c_t bulk collect into v_type_t

11        limit 100;

12    exit when v_type_t.count = 0;

13   dbms_output.put_line(v_type_t.count);

14    v_row :=v_type_t.first;

15    while(v_row is not null)

16     loop

17  --  

dbms_output.put_line(v_type_t(v_row).empno);

18       null;

19       v_row

:=v_type_t.next(v_row);

20     end loop;

21    end loop;

22    close c_t;

23  end;

24  /

100

36

PL/SQL procedure successfully

completed.