如何从SQL*PLUS向shell传递变量
作者:eygle 发表于 2005-04-11 23:23 最后更新于 2006-12-11 12:14 | English Version
版权声明:可以任意转载,转载时请务必以超链接形式标明文章 原始出处和作者信息及 本声明。
http://www.eygle.com/archives/2005/04/eciosqlplusieos.html
论坛上有人问这个问题,说无法通过sqlplus向shell传递变量,写了一个简单的脚本进行折中处理,供参考:
[oracle@jumper oracle]$ cat a.sh 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
我有另一种类似的需求,在sqlplus中执行一段PL/SQL后,得到一个变量,然后再把这个变量的值用host传给shell,上述的两种方式就不适用了。请问有其他方式吗?
Posted by: ArseneFang at June 14, 2005 2:30 PM
To ArseneFang;
可以这样写:
SQL> col inst new_val instance_name
SQL> select instance_name inst from v$instance;
INST
----------------
conner
SQL> host echo &instance_name
conner
Posted by: eygle at June 14, 2005 10:06 PM
沒有留言:
張貼留言