Oracle错误:[:into:unknown operator

时间:2017-10-13 11:25:48

标签: linux oracle shell

我正在编写一个shell脚本,它连接到oracle数据库并执行一些命令。代码如下所示。

mSqlCmd="select *
         from bs_transferSystemRole
         where system_ = '$system'
         and role_type = $roleType
         and abstract_type_desc = '$abstractTypeDesc'"

sqlplus -s $DB_CONNECT <<EOF 2>/dev/null
            WHENEVER SQLERROR EXIT SQL.SQLCODE
            set echo off termout off feedback off heading off
            $mSqlCmd;
            exit SQL.SQLCODE;
EOF

     if [ $? -eq 0 ]
     then
        mSQLCode=`sqlplus -s $DB_CONNECT <<EOF 2>/dev/null
            WHENEVER SQLERROR EXIT SQL.SQLCODE
            set echo off termout off feedback off heading off
            insert into bs_transferSystemRole (system_, role_type,    abstract_type_desc,use_synch_client_logic, multiple_match_option) values ('$system', $roleType, '$abstractTypeDesc','$useSyncClientLogic', $multiMatchOption);
            exit SQL.SQLCODE;
EOF`

if [ $mSQLCode -ne 0 ] // error at this line: [: into: unknown operator
        then
print "Error: Failed to add record to bs_transferSystemRole table for " \
              | tee -a $logFile
else
           print "Record for '$line' added to bs_transferSystemRole table "\
              | tee -a $logFile
fi

当我在具有相应输入文件的linux机器上运行上述脚本时,其中包含代码中的所有相应变量,如果[$ mSQLCode -ne 0],我会在行中收到错误[:into:unknown operator]。

oracle中的Insert into语句是否存在问题。任何帮助,将不胜感激。

1 个答案:

答案 0 :(得分:2)

if [ $mSQLCode -ne 0 ]中的变量mSQLCode必须加双引号,如下所示:if [ "$mSQLCode" -ne 0 ]

原因是mSQLCode是Oracle查询的结果,涉及多行代码(insert into ...)。变量必须加双引号,这意味着必须考虑查询中的多行。