Issuing DELETE Statements in a Loop
DROP TABLE parts1 CASCADE CONSTRAINTS PURGE;
CREATE TABLE parts1 (
pnum INTEGER,
pname VARCHAR2(15));
DROP TABLE parts2 CASCADE CONSTRAINTS PURGE;
CREATE TABLE parts2 (
pnum INTEGER,
pname VARCHAR2(15));
DECLARE
TYPE numtab IS TABLE OF parts1.pnum%TYPE INDEX BY PLS_INTEGER;
TYPE nametab IS TABLE OF parts1.pname%TYPE INDEX BY PLS_INTEGER;
pnums NUMTAB;
pnames NAMETAB;
iterations CONSTANT PLS_INTEGER := 500;
t1 INTEGER;
t2 INTEGER;
t3 INTEGER;
BEGIN
FOR j IN 1.. iterations LOOP -- load index-by tables
Pnums(j) := j;
Pnames(j) := 'Part No. '
||To_char(j);
END LOOP;
t1 := dbms_utility.get_time;
FOR i IN 1.. iterations LOOP -- use FOR loop
INSERT INTO parts1
VALUES (Pnums(i),
Pnames(i));
END LOOP;
t2 := dbms_utility.get_time;
FORALL i IN 1..iterations -- use FORALL statement
INSERT INTO parts2
VALUES (Pnums(i),
Pnames(i));
t3 := dbms_utility.get_time;
dbms_output.Put_line('Execution Time (secs)');
dbms_output.Put_line('---------------------');
dbms_output.Put_line('FOR loop: '
||To_char((t2
- t1)
/ 100));
dbms_output.Put_line('FORALL: '
||To_char((t3
- t2)
/ 100));
COMMIT;
END;
/
OUTPUT:-
Execution Time (secs)
---------------------
FOR loop: .03
FORALL: 0
PL/SQL procedure successfully completed.
0 comments:
Post a Comment