我的IT技术库
===========================================================
轻松掌握如何从sqlplus向shell传递变量
===========================================================

很多人在实际的工作和学习中,都遇到了无法通过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


zjc4u 发表于:2008.01.28 14:55 ::分类: ( Oracle资料 ) ::阅读:(10620次) :: 评论 (0)

发表评论
标题

在此添加评论
表情符号: smile laughing tongue angry crying sad wassat wink

称呼

邮箱地址(可选)

个人主页(可选)




自我介绍
切换风格
新闻聚合
博客日历
文章归档...
最新发表...
博客统计...
网站链接...