您可以重複你的結果集如下:
SQL> select car_model from available_models
2 group by car_model ;
CAR_MODEL
------------------------------
Corsair
Executive
Country Squire
SQL>
重寫你的shell腳本(使用時間)如下:
[[email protected] 1]$ cat test.sh
CONNECT='z_test/welcome1'
VALUE=`sqlplus -s /nolog <<EOF
CONNECT ${CONNECT}
set head off
select car_model from available_models
group by car_model
/
EXIT
EOF`
echo "resultset: "
echo "${VALUE}"
echo " "
echo "now iterate ..."
let rec=0
echo "${VALUE}" |while read line
do
echo "processing $rec: $line"
let rec=rec+1
done
[[email protected] 1]$
這是預期輸出:
[[email protected] 1]$ ./test.sh
resultset:
Corsair
Executive
Country Squire
now iterate ...
processing 0:
processing 1: Corsair
processing 2: Executive
processing 3: Country Squire
請注意,第#0行是空白的,因爲它也是結果集的一部分。
添加「設置頁面大小0」將刪除該空白行:
[[email protected] 1]$ cat test.sh
CONNECT='z_test/welcome1'
VALUE=`sqlplus -s /nolog <<EOF
CONNECT ${CONNECT}
set head off
set pagesize 0
select car_model from available_models
group by car_model
/
EXIT
EOF`
......
預期的運行:
[[email protected] 1]$ ./test.sh
resultset:
Corsair
Executive
Country Squire
now iterate ...
processing 0: Corsair
processing 1: Executive
processing 2: Country Squire
[[email protected] 1]$
問候
要麼沒有數據從查詢或內部的一些錯誤返回for循環;在這種情況下,你可以相應地更新。 – Richard