Optimiser 2 boucles FOR ?
Hello tlm
J'ai 2 tables :
TABLE libelle
lib VARCHAR2
lib
'COMP%'
TABLE entreprise
id_ent NUMBER
nom VARCHAR
id_ent | nom
01 | 'COMPAGNIE INFORMATIQUE'
02 | 'TOTO INC'
Je veux rechercher les lignes de la table Entreprise qui correspondent à chaque libelle.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| DECLARE
CURSOR libcur is select * from libelle;
label libcur%ROWTYPE;
CURSOR entcur is SELECT id_ent, nom FROM entreprise;
ent entcur%ROWTYPE;
BEGIN
FOR label IN libcur
LOOP
FOR ent IN ptcur
LOOP
IF (ent.full_name LIKE label.lib) THEN
DBMS_OUTPUT.PUT_LINE(ent.id_ent || ' - ' || ent.full_name || ' - ' ||label.lib);
END IF;
END LOOP;
END LOOP;
END;
/ |
Pour le moment j'ai laissé l'affichage avec DBMS_OUTPUT mais j'ai vite le buffer qui explose, et ca prend du temps.
Table Entreprise : 550 000 lignes
Table Libelle : 1 600 lignes
Ca fait 880M comparaison, olé !
Par la suite il faudra que j'insere le resultat dans une table.
Jvoulais savoir si vous auriez une idee pour optimiser la comparaison ? Merci