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
|
PROCEDURE CHARGE_TXT IS
cur sys_refcursor ;
TYPE LCO_lst IS TABLE OF SYS.COL$.NAME%TYPE INDEX BY BINARY_INTEGER;
TYPE LDA_lst IS TABLE OF SYS.COL$.NAME%TYPE INDEX BY BINARY_INTEGER;
Llst_col LCO_lst;
Llst_dat LDA_lst;
flog TEXT_IO.FILE_TYPE;
LC_path VARCHAR2(255);
LC_file VARCHAR2(255);
LC_os B0000.VALEUR%TYPE := 'WINDOWS';
LC_index NUMBER(3) := 0;
LD_index NUMBER(3) := 0;
PNAME SYS.COL$.NAME%TYPE;
PCOL SYS.COL$.COL#%TYPE;
PLENGTH SYS.COL$.LENGTH%TYPE;
PTYPE SYS.COL$.TYPE#%TYPE;
PSCALE SYS.COL$.SCALE%TYPE;
PPRECISION SYS.COL$.PRECISION#%TYPE;
P_T_VAR VARCHAR2(10);
ORD_SELECT VARCHAR2(10000);
ORD_WHERE VARCHAR2(20000);
SUIT_WHERE VARCHAR2(20);
TABL VARCHAR2(100);
LIGNE VARCHAR2(32700);
ORDRE VARCHAR2(1000);
CURSOR COLONNES IS
SELECT C.NAME,
C.COL#,
C.LENGTH,
C.TYPE#,
C.SCALE,
C.PRECISION#
FROM SYS.COL$ C
WHERE C.OBJ# = :B1.TRA_OBJ
ORDER BY C.COL#;
BEGIN
BEGIN
SELECT VALEUR
INTO LC_path
FROM B0000
WHERE SYMBOL LIKE 'REPDEF';
EXCEPTION WHEN NO_DATA_FOUND THEN
LC_path := '/vol1/forms/wf60/';
END;
BEGIN
SELECT VALEUR
INTO LC_os
FROM B0000
WHERE SYMBOL LIKE 'OS';
EXCEPTION WHEN NO_DATA_FOUND THEN
LC_os := 'WINDOWS';
END;
IF LC_os = 'UNIX' THEN
LC_path := LC_path || 'TRAV/';
ELSE
LC_path := LC_path || 'TRAV\';
END IF;
LC_file := 'table_'||:B1.TABLE_NAME ||'_'
|| TO_CHAR(SYSDATE, 'YYMMDD_HH24MI') || '.txt';
flog := TEXT_IO.FOPEN(LC_path || LC_file, 'W');
TEXT_IO.PUT(flog,' ');
--Recherche des entêtes de colonnes et des caractéristiques
OPEN COLONNES;
LOOP
FETCH COLONNES
INTO PNAME,
PCOL,
PLENGTH,
PTYPE,
PSCALE,
PPRECISION;
EXIT WHEN COLONNES%NOTFOUND;
TEXT_IO.PUT(flog, PNAME ||' ; ' );
Llst_col(LC_index) := PNAME;
LC_index := LC_index + 1;
BEGIN
SELECT DECODE (PTYPE,1,'CHAR',2, DECODE(PSCALE,NULL,
DECODE(PPRECISION,NULL,'NUMBER','FLOAT'),'NUMBER'),
8,'LONG',9,'VARCHAR',12,'DATE',23,'RAW',24,'LONG RAW',
69,'ROWID','UNDEFINED')
INTO P_T_VAR
FROM DUAL;
END;
IF P_T_VAR = 'DATE'
THEN
Llst_dat(LD_index) := PNAME;
LD_index := Ld_index + 1;
END IF;
END LOOP;
CLOSE COLONNES;
TEXT_IO.PUT_LINE(flog, NULL);
--Select des données de la table
ORD_SELECT := NULL;
FOR LC_j IN Llst_col.FIRST..Llst_col.LAST
LOOP
ORD_SELECT := ORD_SELECT||' '||Llst_col(Lc_j)||','||';'||',';
END LOOP;
MSG_BOX( 'ORD_SELECT '||SUBSTR(ORD_SELECT,1,255));
TABL := :B1.TABLE_NAME;
IF ld_index = 0
then MSG_BOX('pas de where ');
ORD_WHERE := ' rownum > 1' ;
GOTO DEB_SEL;
END IF;
ORD_WHERE := NULL;
SUIT_WHERE := NULL;
FOR LD_j IN Llst_dat.FIRST..Llst_dat.LAST
LOOP
ORD_WHERE := ORD_WHERE||' '||Suit_where||' '||Llst_dat(Ld_j)
||' between '||NVL(:B0.DEBUT,'01-JAN-00')
||' and '||NVL(:B0.FIN,'31-DEC-08') ;
SUIT_WHERE := ' AND ';
END LOOP;
MSG_BOX( 'ORD_WHERE '||SUBSTR(ORD_WHERE,1,255));
ORDRE := 'SELECT '||ord_select|| ' FROM ' ||:B1.TABLE_NAME||' WHERE '||ORD_WHERE ||';' ;
OPEN cur FOR ORDRE;
LOOP
FETCH cur INTO ligne ;
EXIT WHEN cur%NOTFOUND;
TEXT_IO.PUT(flog,ligne);
TEXT_IO.PUT_LINE(flog, NULL);
END LOOP;
CLOSE cur ;
<<FIN>>
TEXT_IO.FCLOSE(flog);
MESSAGE('Le fichier ' || LC_path || LC_file
|| ' a été généré avec succès.', NO_ACKNOWLEDGE);
SYNCHRONIZE;
MSG_BOX('Le fichier ' || LC_file
|| ' a été généré avec succès dans le répertoire TRAV.');
END; |
Partager