2013-11-14 75 views
0

內執行查詢我有殼腳本用下面的代碼:使用循環通過在linux陣列遍歷到SQLPLUS

#! /bin/bash 

MODEL=$1 
declare -a arr=("porsche" "lamborgini" "tesla") 

for i in ${arr[@]} 
do 
sqlplus -s un/pass <<! 
set verify off 
INSERT INTO tbl1 (par1, par2, par3, datetime_parm) 
VALUES('$MODEL', '${arr[i]}', (select count(s) from table i), SYSTIMESTAMP); 
COMMIT; 
exit; 
! 
done 

出於某種原因,它被覆蓋先前的值它從陣列獲取並我結束只用'tesla'填充表格。

有沒有人知道我在做什麼錯?

回答

1

我想通了。

#! /bin/bash 

MODEL=$1 
declare -a arr=("porsche" "lamborgini" "tesla") 

for i in ${arr[@]} 
do 
sqlplus -s un/pass <<! 
set verify off 
INSERT INTO tbl1 (par1, par2, par3, datetime_parm) 
VALUES('$MODEL', '$i', (select count(s) from table i), SYSTIMESTAMP); 
COMMIT; 
exit; 
! 
done 
+0

我只需要通過變量$ i – Angelina