我試圖將cat1.txt作爲變量($ 2),以便它將被插入到sql select語句中。有沒有辦法做到這一點?
從shell腳本傳遞變量到sql語句
my cat1.txt
1111
2334
2234
3333
4444
....
....
etc.
我的SQL語句
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
我想試試這個,請參見下文。而不是手動鍵入prod_bill使其像文件名一樣變量。任何我應該添加到我的shell腳本?感謝:-)
from prod_trans
where m_date = 11 and day >= 23 and day <= 30
and (prod_bill) in ($2)
我的shell腳本
#!/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/[email protected]$ORACLE_SID @$SCRIPT/log.sql $FILENM
什麼版本的Oracle? – 2009-12-18 05:20:29