Übergeben variable aus shell-Skript, um sql-Anweisung
Ich habe versucht zu machen cat1.txt als variable ($2), so dass es eingefügt wird in sql-select-Anweisung. Gibt es eine Möglichkeit, dies zu tun?
my cat1.txt
1111
2334
2234
3333
4444
....
....
etc.
my SQL-Anweisung
set echo off linesize 280 pagesize 0 newpage 0 feedback 1 verify off head off trimspool on
alter session set sort_area_size=104857600;
define filename = &1
spool &&filename
prompt DATE TIME Service Name Amount
select trim(to_char(trans_time,'yyyymmdd')) || chr(9) ||
trim(to_char(trans_time,'hh24miss')) || chr(9) ||
trim(prod_name)|| chr(9) ||
(prod_price)
where m_date = 11 and day >= 23 and day <= 30
and (prod_bill) in ('1111','2334','2234','3333','4444')
/
spool off
exit
Ich möchte versuchen, diese,siehe unten. Statt der manuellen Eingabe der prod_bill machen es so variabel wie der Dateiname. Alles, was ich hinzufügen sollte, um mein shell-Skript aus? Vielen Dank 🙂
from prod_trans
where m_date = 11 and day >= 23 and day <= 30
and (prod_bill) in ($2)
MEIN SHELL-SKRIPT
#!/bin/sh
export ORACLE_BASE=/u01/app/oracle
export ORACLE_SID=prod
export ORACLE_HOME=/u01/app/oracle/product/9.2.0
export ORACLE_BASE ORACLE_HOME ORACLE_SID
export PATH=$PATH:/usr/local/bin:$ORACLE_HOME/bin:/usr/sbin:/opt/java1.5/bin
export USERNAME=prods
export PASSWORD=prods
export OUT_PATH=/home/prod/reports/adhoc/REp
export SCRIPT=$OUT_PATH/BICScripts/Translog
export OUTPUT=/home/prod/reports/adhoc/REp/Scripts/log/OUTPUT
export FILENM=$OUTPUT/log_`date +%y%m%d`.txt
sqlplus -s $USERNAME/$PASSWORD@$ORACLE_SID @$SCRIPT/log.sql $FILENM
Welche version von Oracle?
Hast du Sie gefunden?
Hast du Sie gefunden?
InformationsquelleAutor Cez | 2009-12-18
Du musst angemeldet sein, um einen Kommentar abzugeben.
hoffe, es löst das problem, und ich antwortete richtig.
InformationsquelleAutor Venkataramesh Kommoju
Ich habe keine Ahnung, ob es eine Möglichkeit zum Zugriff auf Oracle-db-shell-Skript, aber Sie können verwenden Sie zum Beispiel Perl? Ich denke, das wäre ziemlich einfach zu tun, mit DBI Zugriff auf die db.
Natürlich können Sie einfach analysieren .sql -Datei mittels shell-Skript zum hinzufügen von prod_bills cat1.txt gerade zu es.
InformationsquelleAutor Illotus