在读取大量数据游标时,速度十分慢!然而使用fetch bulk collect into 批量效率能有效提高读取游标速度:
例如:
CREATE OR REPLACE PROCEDURE "WINBO_DELETE_PUR_REQ"
Is
Type winbo Is Table Of purchase_requisition_tab.REQUISITION_NO%Type;
winbo_ winbo;
CURSOR get_requisition_no IS
Select A.REQUISITION_NO
From PURCHASE_REQUISITION A
Where A.REQUISITIONER_CODE!='MRP'
And Not Exists (Select 1 From PURCHASE_REQ_LINE_PART B
Where B.requisition_no=A.requisition_no)
And Not Exists (Select 1 From PURCHASE_REQ_LINE_NOPART c
Where c.requisition_no=A.requisition_no);
begin
-- Test statements here:如些进行循环操作数据,速度十分慢
/*FOR rec_ IN get_requisition_no LOOP
BEGIN
Delete FROM purchase_requisition_tab WHERE REQUISITION_NO =rec_.requisition_no ;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('error:'||Sqlerrm||'requisition_no:'||rec_.requisition_no); END;
END LOOP; */
--Forall i IN 1..winbo_.Count:利用fetch bulk collect into批量读取数据,提高速度
Open get_requisition_no;
Fetch get_requisition_no Bulk Collect Into winbo_ ;
Forall i In winbo_.First..winbo_.Last
Delete FROM purchase_requisition_tab WHERE REQUISITION_NO = winbo_(i);
close get_requisition_no;
End winbo_delete_pur_req;
/