使用shell脚本从sql脚本中选择列到局部变量中 [英] Select columns into local variable from sql script using shell script

查看:25
本文介绍了使用shell脚本从sql脚本中选择列到局部变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将从表中检索到的列值存储到我的 shell 脚本中的变量中.

How do I stores columns values retrieved from a table into a variable in my shell script.

我有以下代码:

#!/usr/bin/ksh

echo "This script will try to connect to sql plus and displays the date"
echo

sqlplus user/password << EOF
SELECT sysdate 
from dual;
EOF
exit;

echo "End of SQL"

我需要将 sysdate 的值存储到一个局部变量并回显它.我该怎么做?

I need to store the value of sysdate to a local variable and echo it. How do I do that?

推荐答案

这对我有用.

    #!/usr/bin/ksh

clear

echo "This will print the Date"

VALUE=`sqlplus -silent apps/Z4vRD3me <<END
set pagesize 0 feedback off verify off heading off echo off
select sysdate from dual 
exit;
END`


# xx=$(echo 'select sysdate from dual' | sqlplus -silent apps/Z4vRD3me)

echo $VALUE

echo "End of SQL"

这篇关于使用shell脚本从sql脚本中选择列到局部变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆