1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| -- table de test table_test
CREATE TABLE table_test (id NUMBER);
/
-- peupler la table avec 999 archives
INSERT INTO table_test
SELECT LEVEL
FROM dual
CONNECT BY LEVEL < 1000
/
DECLARE
-- compteur universel pour déterminer COMMIT temps
l_compteur INTEGER := 0;
-- compteur pour toutes l'archives efface
l_lignes_affectées PLS_INTEGER := 0;
-- le numero d'archives touché par un COMMIT operation
c_étape CONSTANT PLS_INTEGER := 50;
-- la procedure efface une archive et efectuer un COMMIT operation
PROCEDURE effacer(p_id NUMBER)
IS
l_compteur_tmp PLS_INTEGER;
BEGIN
l_compteur := l_compteur + 1;
DELETE FROM table_test WHERE ID = p_id;
l_lignes_affectées := l_lignes_affectées + SQL%ROWCOUNT;
IF MOD(l_compteur, c_étape) = 0 THEN
COMMIT;
DBMS_OUTPUT.PUT_LINE('COMMIT ' || c_étape || ' modifications');
END IF;
END effacer;
BEGIN
-- boucle principal
FOR v_rec IN (SELECT ID FROM table_test) LOOP
effacer(v_rec.id);
END LOOP;
COMMIT;
DBMS_OUTPUT.PUT_LINE('lignes affectées ' || l_lignes_affectées);
END;
/ |
Partager