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 65 66 67 68
|
set serveroutput on size 1000000;
spool &1.log;
declare
-- Paramètres :
P_Codsoc number(3) := &2;
-- Pointeurs fichiers :
Spoint UTL_FILE.FILE_TYPE;
begin
dbms_output.put_line('Création du fichier');
-- Création du fichier
Spoint := UTL_FILE.FOPEN('/gnxdevcan/out/fm/cedilac','test.sd','W');
dbms_output.put_line('Fichier créé');
-- Lecture de la base
dbms_output.put_line('Lecture de la base');
begin
for curCrit in
(
select lpad(decode(tbl.codtbl,
'047', '9',
'050', '5',
'051', '11',
'052', '8',
'053', '3',
'059', '6',
'060', '16',
'061', '10',
'209', '15',
'uni', '2'
), 2, '0') numcrit, tbl.cletbl, decode(ttu.cletbl, '052', tbl.lib1, tbl.lir) libtbl, ttu.lir nomcrit
from tbl ttu
inner join tbl on tbl.codsoc = ttu.codsoc and tbl.codtbl = lower(ttu.cletbl)
where ttu.codsoc = P_Codsoc
and ttu.codtbl in ('tbl', 'ttu')
and ttu.cletbl in ('047', '050', '051', '052', '053', '059', '060', '061', '209', 'UNI')
union all
select '04', codefam, lirfam, 'Fam Prod'
from fam
where codsoc = P_Codsoc
and typtie = 'PRO'
)
loop
-- Insertion de la ligne dans le fichier
dbms_output.put_line('On écrit une ligne...');
UTL_FILE.PUTF(Spoint, '%s;"%s";"%s";"%s"\n', curCrit.numcrit, curCrit.cletbl, curCrit.libtbl, curCrit.nomcrit);
end loop;
dbms_output.put_line('Fin de lecture de la base');
exception
when NO_DATA_FOUND then
dbms_output.put_line('Aucune donnée trouvée');
when OTHERS then
dbms_output.put_line(sqlerrm);
end;
-- Fermeture du fichier
dbms_output.put_line('Fermeture du fichier');
UTL_FILE.FCLOSE(Spoint);
end;
/ |
Partager