如何在 ksh shell 脚本的 if 条件下编写 sql 查询

how to write sql query in if condition of ksh shell script

我是 shell 脚本编写的新手,我想在 IF 'condition' 中编写一个 SQL 查询,而不是在 if 'block' 中。有人可以帮我吗?

我的代码:-

if [sqlplus -s /@user_pass_dbname << EOF select param_value from my_table where my_id=1 EXIT; /EOF == '7878'];then
echo "works!!"
else
echo "doesn't work"

输出:- 第 3 行的语法错误:`<<' 不匹配

我现在没有测试环境,但我认为你需要加引号(')。

    'sqlplus -s /@user_pass_dbname << EOF select param_value from my_table 
    where my_id=1 EXIT; /EOF'

改为从变量中的 sqlplus 获取值:

result=`sqlplus -s /@user_pass_dbname <<EOF
set head off feedback off
select param_value from param_table where param_id=1;
exit
EOF`

if [ $result = 965 ]; then
 echo "works"
else
 echo "doesn't work"
fi