我正在运行Shellscript来更新数据库,但收到错误“ ORA-00928:缺少SELECT关键字” 。但是在执行选择查询时它可以正常工作。我没有什么问题吗?
使用选择查询执行脚本:
./dbScript.sh "select columnName from tableName where uniqueColumnName = 'XYZ'" <setEnvFilePath>
使用更新查询执行脚本:
./dbScript.sh "UPDATE tableName SET columnName = columnName - interval '45' day WHERE uniqueColumnName = 'XYZ'" <setEnvFilePath>
dbScript.sh
#!/bin/bash
function setEnvDetails()
{
if [[ $JAVA_HOME = "" || $WL_HOME = "" ]]; then
echo "Please set environment variables JAVA_HOME and WL_HOME."
echo "Exiting..." && exit 1
fi
LOGIN_NM=${DB_USER_ROOT}/${DB_PASSWORD}@$DB
}
cd $2
. ./setEnv.sh
setEnvDetails
query=$1
#echo $query
sqlplus -s $LOGIN_NM <<!
set echo off;
set feedback off;
set pagesize 0;
set trimspool off;
($query);
!
setEnv.sh
#!/bin/ksh
#----------------------------------------------------------------------------
# Set user-defined variables.
# these values are taken from env_user.properties at installation time
#----------------------------------------------------------------------------
export JAVA_HOME=/nfs/tools/jdk/linux/jdk1.8.0_25-x64
if [ "${MEM_ARGS}" = "" ] ; then
export MEM_ARGS="-Xms1024m -Xmx1024m -XX:MaxPermSize=512m -
XX:PermSize=512m -verbose:gc"
fi
export WL_HOME=/nfs/tools/bea/12.c/12.c/wlserver_12.1/
export DB_USER_ROOT=abcd11111
export DB_PASSWORD=abcd11111
export DB=sidev11g
export OM_DB_TYPE=ORACLE
export ORACLE_HOME=/nfs/tools/oracle/linux_64/11.2.0
export TNS_ADMIN=/nfs/tools/oracle/linux_64/11.2.0/network/admin
export THIN_URL=punvm-oracle03.sigmasys.net:1522:si12c
#export NLS_LANG=@nls.lang@
PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
答案 0 :(得分:0)
问题是 dbScript.sh
中的这一行($query);
您只能在子查询(以SELECT开头)周围加上括号。 This is fine with SELECT,但is not valid with UPDATE。更改为此:
$query;