开发者

Select columns into local variable from sql script using shell script

开发者 https://www.devze.com 2023-01-24 16:37 出处:网络
How do I stores columns values retrieved from a table into a variable in my shell script. I have the following code:

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

I have the following code:

#!/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"

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


This worked for me.

    #!/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"
0

精彩评论

暂无评论...
验证码 换一张
取 消