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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
SET SERVEROUTPUT ON SIZE 200000
SET VERIFY OFF
SET FEEDBACK OFF
SET COLSEP '|'
SET head ON
Declare
lv_name VARCHAR2(100);
lv_rep VARCHAR2(250) := '/usr/tmp';
vv_separator VARCHAR2(2) := '|';
ln_compteur_lignes NUMBER := 0; -- nombre de lignes inserees dans le fichier
vv_entete VARCHAR2(2500);
vv_buffer VARCHAR2(2500);
lt_id UTL_FILE.FILE_TYPE;
lv_err_msg VARCHAR2(250);
pv_errbuff VARCHAR2 (250):= null;
pn_retcode NUMBER := 0 ;
lv_affactureur VARCHAR2(150);
cv_line VARCHAR2(100) := '=======================================================';
----fournisseur contact
CURSOR cur_contact_BPACK IS
select distinct
pvsa.vendor_site_id,
null "Clé interne",
pvc.last_name "Nom",
pvc.first_name "Prénom",
pvc.title "Fonction",
pv.segment1 "Fournisseur",
pvc.area_code || pvc.phone "Tél",
pvc.ALT_AREA_CODE ||alt_phone "Tél mobile",
pvc.fax_area_code || pvc.fax "Fax",
pvc.email_address "eMail",
null "Désactivé",
null "Créé par",
null "Date de création",
null "Modifié par",
null "Date de modification"
from po_vendor_contacts pvc,
po_vendors pv,
po_vendor_sites_all pvsa,
gl_code_combinations gcc
where pvc.vendor_site_id = pvsa.vendor_site_id
and pvsa.vendor_id = pv.vendor_id
and pvsa.pay_group_lookup_code like '%FG%' --frais généraux
and pvsa.accts_pay_code_combination_id=gcc.code_combination_id --dette fournisseur compte
and gcc.segment3=401137 --frais généraux et fournisseur compte =401137
and pvsa.inactive_date is null --actif
and pv.end_date_active is null --actif
and pvsa.org_id=128
and pvsa.vendor_site_id in (select pvsa.vendor_site_id
from po_vendor_sites_all pvsa,
ap_bank_accounts_all abaa,
ap_bank_account_uses_all abaua
where 0=0
and abaua.vendor_site_id=pvsa.vendor_site_id (+)
and abaa.bank_account_id=abaua.external_bank_account_id
and abaa.currency_code='EUR'
and abaua.primary_flag='Y'
);
--fournisseurs de FRP
rec_contact_BPACK cur_contact_BPACK%ROWTYPE;
BEGIN
BEGIN
ln_compteur_lignes := 0;
dbms_output.put_line('Creation et Ouverture du fichier Contact en lecture');
lv_name := 'B_PACK_CONTACT' || TO_CHAR(SYSDATE, 'DDMMYYYY_HH24MISS') || '.cvs';
dbms_output.put_line ( lv_name );
lt_id := UTL_FILE.FOPEN(lv_rep, lv_name, 'w');
IF UTL_FILE.IS_OPEN(lt_id) THEN
dbms_output.put_line (cv_line);
dbms_output.put_line('Creation OK du fichier: ' || lv_name);
ELSE
dbms_output.put_line(cv_line);
dbms_output.put_line('Probleme ouverture du fichier ' ||lv_name);
END IF;
EXCEPTION
WHEN UTL_FILE.WRITE_ERROR THEN
UTL_FILE.FCLOSE(lt_id);
pv_errbuff := SQLERRM;
pn_retcode := SQLCODE;
dbms_output.put_line('erreur write_error!');
WHEN UTL_FILE.INVALID_PATH THEN
UTL_FILE.FCLOSE(lt_id);
pn_retcode := SQLCODE;
pv_errbuff := SQLERRM;
dbms_output.put_line('invalid_path!!');
END;
BEGIN
vv_entete :='Clé interne'||vv_separator||
'Nom'||vv_separator||
'Prénom'||vv_separator||
'Fonction'||vv_separator||
'Fournisseur'||vv_separator||
'Tél'||vv_separator||
'Tél mobile'||vv_separator||
'eMail'||vv_separator||
'Désactivé'||vv_separator||
'Créé par'||vv_separator||
'Date de création'||vv_separator||
'Modifié par'||vv_separator||
'Date de modification'||vv_separator;
UTL_FILE.PUT_LINE(lt_id, vv_entete);
OPEN cur_contact_BPACK;
LOOP
FETCH cur_contact_BPACK
INTO rec_contact_BPACK;
EXIT WHEN cur_contact_BPACK%NOTFOUND;
BEGIN
vv_buffer := RPAD(NVL(rec_contact_BPACK."Clé interne", ' '), 3) ||vv_separator||
RPAD(NVL(rec_contact_BPACK."Nom", ' '), 20) ||vv_separator||
RPAD(NVL(rec_contact_BPACK."Prénom", ' '), 30) ||vv_separator||
RPAD(NVL(rec_contact_BPACK."Fonction", ' '), 15) ||vv_separator||
RPAD(NVL(rec_contact_BPACK."Fournisseur", ' '), 9) ||vv_separator||
RPAD(NVL(rec_contact_BPACK."Tél", ' '), 20) ||vv_separator||
RPAD(NVL(rec_contact_BPACK."Tél mobile", ' '), 20) ||vv_separator||
RPAD(NVL(rec_contact_BPACK."Fax", ' '), 20) ||vv_separator||
RPAD(NVL(rec_contact_BPACK."eMail", ' '), 50) ||vv_separator||
RPAD(NVL(rec_contact_BPACK."Désactivé", ' '), 12) ||vv_separator||
RPAD(NVL(rec_contact_BPACK."Créé par", ' '), 12) ||vv_separator||
RPAD(NVL(rec_contact_BPACK."Date de création", ' '), 12) ||vv_separator||
RPAD(NVL(rec_contact_BPACK."Modifié par", ' '), 12) ||vv_separator||
RPAD(NVL(rec_contact_BPACK."Date de modification", ' '), 12) ;
UTL_FILE.PUT_LINE(lt_id, vv_buffer);
ln_compteur_lignes := ln_compteur_lignes + 1;
END;
END LOOP;
dbms_output.put_line (to_char(ln_compteur_lignes) ||
' lignes inserees dans le fichier ' ||lv_rep||'/'
|| lv_name);
CLOSE cur_contact_BPACK;
UTL_FILE.FCLOSE(lt_id);
dbms_output.put_line(' ');
dbms_output.put_line(cv_line);
EXCEPTION
WHEN OTHERS THEN
pn_retcode := SQLCODE;
ROLLBACK;
dbms_output.put_line ('error'||SQLCODE);
UTL_FILE.FCLOSE(lt_id);
END ;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line ('Une Erreur arrive lors que l''extraction du CONTACT!!');
END; |
Partager