d;
end loop;
dbms_output.put_line(c1%rowcount||' row deleted.');
close c1;
end;
/
性能数据:
------------
delete from robo
where
rowid=:1
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1909760 113.98 154.81 36737 2053459 2121671 1909760
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 1909761 113.98 154.81 36737 2053459 2121671 1909760
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 52 (recursive depth: 1)
Rows Row Source Operation
------- ---------------------------------------------------
1909760 DELETE ROBO (cr=2053679 pr=36737 pw=0 time=79817096 us)
1909760 TABLE ACCESS BY USER ROWID ROBO (cr=2053394 pr=36266 pw=0 time=12527588 us)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
db file sequential read 36735 0.00 0.22
log file switch completion 21 0.97 12.30
log file switch (checkpoint incomplete) 72 0.97 30.14
********************************************************************************
declare
type var_tab is table of varchar2(25) index by pls_integer;
v_rowid var_tab;
v_sqltext varchar2(200);
cursor c1 is select rowid from robo where owner='SYS';
begin
v_sqltext := 'delete from robo where rowid=:1';
open c1;
loop
fetch c1 bulk collect into v_rowid limit 50000;
for i in 1..v_rowid.count loop
execute immediate v_sqltext using v_rowid(i);
end loop;
exit when c1%notfound;
end loop;
dbms_output.put_line(c1%rowcount||' row deleted.');
close c1;
end;
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 49.21 47.42 0 0 0 1
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 49.21 47.42 0 0 0 1
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 52
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 2 0.00 0.00
SQL*Net message from client 2 0.00 0.00
********************************************************************************
SELECT ROWID
FROM
ROBO WHERE OWNER='SYS'
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 39 2.48 2.42 126813 221222 1 1909760
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 41 2.48 2.42 126813 221222 1 1909760
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 52 (recursive depth: 1)
Rows Row Source Operation
------- ---------------------------------------------------
1909760 TABLE ACCESS FULL ROBO (cr=221222 pr=126813 pw=0 time=1910539 us)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
db file sequential read 306 0.00 0.00
db file scattered read 7945 0.00 0.47
latch: object queue header operation 2 0.00 0.00
db file parallel read 1 0.00 0.00
全表扫描一次,但由于是批量提取数据(每次定为5万条)提高,减少提取次数,比起上一种方法节省了很