Oracle错误:[:成:未知运算符 [英] Oracle error: [: into: unknown operator
问题描述
我正在编写一个Shell脚本,该脚本连接到oracle数据库并执行一些命令.代码如下.
I m writing a shell script which connects to oracle database and executes few commands. The code looks as below.
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].
When I run the above script on a linux machine with appropriate input file, which contains all the appropriate variables in the code, I get an error [: into: unknown operator at the line if [ $mSQLCode -ne 0 ].
Oracle中的Insert into语句是否有问题.任何帮助,将不胜感激.
Is the problem with the Insert into statement in the oracle. Any help would be appreciated.
推荐答案
if [ $mSQLCode -ne 0 ]
行中的变量mSQLCode必须用双引号引起来,如下所示:if [ "$mSQLCode" -ne 0 ]
.
The variable mSQLCode in the line if [ $mSQLCode -ne 0 ]
must be double quoted which looks as follows: if [ "$mSQLCode" -ne 0 ]
.
原因是mSQLCode是Oracle查询的结果,该查询涉及多行代码(insert into ...
).变量必须用双引号引起来,这意味着必须考虑查询中的多行.
The reason being mSQLCode is the result of a an Oracle query which involves multiple lines of code (insert into ...
). The variables must be double quoted which means that multiple lines in the query must be considered.
这篇关于Oracle错误:[:成:未知运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!