論壇上有人問這個問題,說無法通過sqlplus向shell傳遞變量,寫了一個簡單的腳本進行折中處理,供參考:
[oracle@jumper oracle]$ cat a.shsqlplus -S "/ as sysdba" << !set heading offcol today noprintcolumn today new_val datselect to_char( sysdate, 'yyyy-mm-dd') today from dual;host echo 'today is ' &datexit;exit;![oracle@jumper oracle]$ ./a.shtoday is 2005-04-11[oracle@jumper oracle]$itpub上的Toms_zhang朋友提供了另外一種方法:
[oracle@jumper oracle]$ more a.sh#!/bin/kshVALUE=`sqlplus -silent "/ as sysdba" < < ENDset pagesize 0 feedback off verify off heading off echo offselect max(sequence#) from v\\\$log_history;exit;END`if [ -z "$VALUE" ]; thenecho "No rows returned from database"exit 0elseecho "Max Sequence Number: $VALUE"fi[oracle@jumper oracle]$ ./a.shMax Sequence Number: 17