如何从SQL*PLUS向shell传递变量
论坛上有人问这个问题,说无法通过sqlplus向shell传递变量,写了一个简单的脚本进行折中处理,供参考:
[oracle@jumper oracle]$ cat a.shitpub上的Toms_zhang朋友提供了另外一种方法:
sqlplus -S "/ as sysdba" << !
set heading off
col today noprint
column today new_val dat
select to_char( sysdate, 'yyyy-mm-dd') today from dual;
host echo 'today is ' &dat
exit;
exit;
!
[oracle@jumper oracle]$ ./a.sh
today is 2005-04-11
[oracle@jumper oracle]$
[oracle@jumper oracle]$ more a.sh
#!/bin/ksh
VALUE=`sqlplus -silent "/ as sysdba" < < END
set pagesize 0 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 0
else
echo "Max Sequence Number: $VALUE"
fi
[oracle@jumper oracle]$ ./a.sh
Max Sequence Number: 17