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 53 54 55 56 57 58 59 60 61 62 63 64
|
CREATE OR REPLACE PROCEDURE MiseAJour (test_result in varchar2) IS
-- declaration des constantes, variables, curseurs et exceptions
i integer; num1 integer; num2 integer; pos_fich1 integer; pos_fich2 integer; anc_position integer; position integer;
chaine1 varchar2(20); chaine2 varchar2(20); buffer varchar2(20); buffer1 varchar2(20); buffer2 varchar2(20); buffAux varchar2(1500);
champ varchar2(20);
echange boolean;
fich_resultat UTL_FILE.FILE_TYPE;
cursor avion_cur is select NumAv from Avion order by NumAv;
BEGIN
-- creation du descripteur du fichier
fich_resultat := UTL_FILE.FOPEN ('REPERTOIRE', 'test_result', 'r');
UTL_FILE.GET_LINE(fich_resultat, buffer1);
-- tri des lignes du fichier test_result
while echange loop
echange := true;
loop
begin
UTL_FILE.GET_LINE(fich_resultat, buffer2);
exception
when no_data_found then exit;
end;
pos_fich1 := instr (buffer1, ' ');
pos_fich2 := instr (buffer1, ' ');
chaine1 := substr (buffer1, 0, pos_fich1 -1);
chaine2 := substr (buffer2, 0, pos_fich2 -1);
num1 := to_number(chaine1);
num2 := to_number(chaine2);
if (num1 > num2) then
buffAux := buffer1;
buffer1 := buffer2;
buffer2 := buffAux;
echange := false;
end if;
end loop;
end loop;
-- lecture du fichier et insertion des données dans la table Avion
loop
begin
UTL_FILE.GET_LINE(fich_resultat, buffer);
exception
when no_data_found then exit;
end;
-- mise à jour de la table Avion
i:=1;
position := instr (buffer, ' ', 1, i);
for cur in avion_cur loop
-- traitement du buffer champ par champ en utilisant les deux fonctions substr et instr
while (position != 0) loop
anc_position := position;
position := instr (buffer, ' ', 1, i);
champ := substr(buffer, anc_position+1, position -1);
end loop;
end loop;
commit;
end loop;
commit;
-- Fermeture du fichier
UTL_FILE.FCLOSE(fich_resultat);
-- declaration des exceptions
END;
/ |
Partager