IF sur une variable SHELL dans un bout de SQL
Bonjour à tous,
Je souhaiterai obtenir des conseils au sujet d'un petit souci que j'ai en ce moment.
En fait, j'exécute un script shell qui entre autre, fait appel à un bout de SQL pour extraire un fichier (dont le chemin et le nom sont stockés dans une table)
Jusque là tout va bien, et le passage de variable du shell au SQL après m'avoir un peu fait galérer est géré.
Maintenant, j'essaye d'affiner un aspect : sur le nommage du fichier que j'extrait (je le récupère, puis le renomme et l'envoie ailleurs).
Pour affiner le nommage du fichier, il faudrait que je puisse au sein du SQL tester une condition mais sur une variable issue du shell.
Voilà (en partie) le code :
Code:
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
|
if [ $PROG = NomPROG_ORACLE ]
then
SORTIE=''
cat << EOD2 | sqlplus -silent $APPS_USER/$APPS_PASS 1>&2
whenever sqlerror exit sql.sqlcode
whenever oserror exit oscode
DECLARE
fin varchar2(1);
BEGIN
LOOP
select phase_code INTO fin
from
FND_CONCURRENT_REQUESTS fcr, FND_CONCURRENT_PROGRAMS fcp
where
fcr.CONCURRENT_PROGRAM_ID=fcp.CONCURRENT_PROGRAM_ID
and
fcp.CONCURRENT_PROGRAM_NAME='NomPROG1_ORACLE'
and
PARENT_REQUEST_ID = '$REQUEST_ID';
exit when fin='C';
END LOOP;
END;
/
set term off
set echo off
set feed off
set verify off
set pages 0
set line 500
spool ${TEMP_DIR}/cpc.sh
select 'cp ' || OUTFILE_NAME || ' /CHEMIN/FICHIER_' || '$PROGPAR3' || '.txt'
INTO :SORTIE
from
FND_CONCURRENT_REQUESTS fcr, FND_CONCURRENT_PROGRAMS fcp
where
fcr.CONCURRENT_PROGRAM_ID=fcp.CONCURRENT_PROGRAM_ID
and
fcp.CONCURRENT_PROGRAM_NAME='GLLEZL'
and
PARENT_REQUEST_ID = '$REQUEST_ID';
spool off
exit
EOD2
chmod 777 ${TEMP_DIR}/cpc.sh
${TEMP_DIR}/cpc.sh
fi |
Je teste en shell dès le début en fait le nom d'un prog que j'aurai lancé (un concurrent program au sens Oracle Appli pour être précis)
Puis intervient le bout de SQL qui me permet de récupérer le fichier de sortie de ce prog pour aller le mettre ailleurs
L'affinage dont je parle serait au milieu de ce code savoir s'il est possible d'aller tester autre chose du genre :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
......
set pages 0
set line 500
spool ${TEMP_DIR}/cpc.sh
---->bout de shell si y'a moyen :
if [ $AUTREVAR = AutreValeur ]
then
select 'cp ' || OUTFILE_NAME || ' /CHEMIN/FICHIER_' || '$AutreChose' || '.txt'
INTO :SORTIE
from
FND_CONCURRENT_REQUESTS fcr, FND_CONCURRENT_PROGRAMS fcp
where
fcr.CONCURRENT_PROGRAM_ID=fcp.CONCURRENT_PROGRAM_ID
and
.....
fi
..... |
Voilà, j'espère que c'est suffisament clair, la question étant simplement : est-il possible d'insérer du shell au sein de SQl, ou faudra-t-il que je fasse un équivalent "if, then" en SQL en passant par des variables SQL qui seraient créées à partir de mes variables shell.
Merci à tous!
A+
Nico