使用shell脚本从sql脚本中选择列到本地变量
问题描述:
如何将从表中检索到的列值存储到shell脚本中的变量中。使用shell脚本从sql脚本中选择列到本地变量
我有以下代码:
#!/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的值保存到一个局部变量和回声它。我怎么做?
答
这对我有效。
#!/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"