devo script di shell che richiama il seguente script SQL:valore restituito da script SQL per shell script di
INSERT INTO SEMANTIC.COUNT_STATISTICS (...);
UPDATE SEMANTIC.COUNT_STATISTICS
SET PRNCT_CHANGE = 1.1;
--want to store result of this bellow select statement in model_count variable
select PRNCT_CHANGE
FROM SEMANTIC.COUNT_STATISTICS
WHERE model = '&MY_MODEL'
AND NEW_DATE = (
select max(NEW_DATE)
from SEMANTIC.COUNT_STATISTICS
where MODEL = '&MY_MODEL'
);
Ora, come faccio a restituire questa variabile PERCENTAGE_NUMBER di nuovo al mio script di shell?
mio script di shell è la seguente:
#!/bin/bash
#
# setup oracle, java, and d2rq environment
. /etc/profile.d/oracle.sh
. /etc/profile.d/java.sh
. /etc/profile.d/d2rq.sh
cd /opt/D2RQ
model_count=$(sqlplus user/pass @count.sql 'MODEL')
if ["$model_count" > 0]; then
echo "percentage count is positive"
else
echo "its negative"
Vorrei per questo ultimo risultato istruzione SELECT da memorizzare nella mia variabile model_count in script di shell.
Qualcuno sa perché non funziona?
C'è un esempio ksh [qui] (http://asktom.oracle.com/pls/asktom/f/f?p=100:11:0::::P11_QUESTION_ID:430819636473). Non sono sicuro se verrà eseguito in bash (molto poca esperienza * nix) ma c'è anche qualche discussione bash sulla pagina. Fondamentalmente l'esempio usa sed e grep per estrarre il risultato della query da tutti gli output di SQLPlus. –