很多人在實際的工作和學習中
都遇到了無法通過sqlplus向shell傳遞變量
下面我們來介紹一個實例腳本來進行折中處理
[oracle@jumper oracle]$ cat ash
sqlplus S / as sysdba << !
set heading off
col today noprint
column today new_val dat
select to_char( sysdate yyyymmdd) today from dual;
host echo today is &dat
exit;
exit;
!
[oracle@jumper oracle]$ /ash
today is
[oracle@jumper oracle]$
下面我們再來介紹另一個實例方法
[oracle@jumper oracle]$ more ash
#!/bin/ksh
VALUE=`sqlplus silent / as sysdba < < END
set pagesize feedback off verify off heading off echo off
select max(sequence#) from v\\\$log_history;
exit;
END`
if [ z $VALUE ]; then
echo No rows returned from database
exit
else
echo Max Sequence Number: $VALUE
fi
[oracle@jumper oracle]$ /ash
Max Sequence Number:
From:http://tw.wingwit.com/Article/program/Oracle/201311/17318.html