一尘不染

如何在Shell脚本中运行SQL

sql

设置变量时如何在Shell脚本中运行SQL命令?我试过这种方法,它不执行命令,它认为命令只是一个字符串。

#!/bin/ksh
variable1=`sqlplus -s username/pw@oracle_instance <<EOF
SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF
select count(*) from table;
EXIT;
EOF`
if [ -z "$variable1" ]; then
  echo "No rows returned from database"
  exit 0
else
  echo $variable1
fi

阅读 170

收藏
2021-05-23

共1个答案

一尘不染

#!/bin/ksh
variable1=$( 
echo "set feed off
set pages 0
select count(*) from table;
exit
"  | sqlplus -s username/password@oracle_instance
)
echo "found count = $variable1"
2021-05-23