SQL查询在运行shell脚本时返回0,但检查DB时6
我正在尝试运行一个带有SQL查询的Shell脚本。现在,由于故事要求,我无法在Shell脚本中使用SQL脚本。我一直在尝试获取shell脚本以返回正确的计数,即“ 6”,但它只是返回“ 0”。
#!/bin/ksh
. /apps/path/config/setenv.ksh
DATE=`date "+%m%d%Y`
returnMessage="`sqlplus username/password@$ORACLE_SID << EOF
WHENEVER OSERROR EXIT SQL.OSCODE ;
WHENEVER SQLERROR EXIT SQL.OSCODE ;
spool /apps/path/data/test.txt
SET HEADING OFF
SET FEEDBACK OFF
SET VERIFY OFF
SET ECHO ON
SET PAGES 0
SET LINESIZE 90
select count(*) from table where dt = to_date('06/18/2020','MM/DD/YYYY');
EOF
`
"
exitCode=$?
oracleError=`echo "$returnMessage" | grep ORA-`
if [ -n "$oracleError" -o "$exitCode" -ne 0 ]; then
log "An error occurred while looking up the $COUNT"
log "SQLPlus Exit Code = $exitCode"
log "SQLPlus Message is: $returnMessage"
return 1
fi
export COUNT=`echo $returnMessage"
return 0
输出也下方给出了
SQL> SET HEADING OFF
SQL> SET FEEDBACK OFF
SQL> SET VERIFY OFF
SQL> SET ECHO ON
SQL> SET PAGES 0
SQL> SET LINESIZE 90
SQL>
SQL> select count(*) from table where dt = to_date('06/18/2020','MM/DD/YYYY');
0
SQL>
我正在使用的输出和代码。不确定问题在哪里,因为查询应返回6;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
un
提交
TED数据仅在创建它的会话中可见(并且,如果没有CONDE> CONDE> CONDE> CONDE> CODER
在会话结束时将可见。泰德)。如果您看不到另一个会话中的数据(即SQL*ins shell中调用),请确保您已在SQL客户端中发布commit
命令,其中insert 数据。
注意:即使您将作为同一用户连接,这也将创建一个单独的会话,并且您将无法在另一个会话中看到未承诺的数据。,
如果您已发出
commits and仍然看不到数据,然后确保SQL客户端和Shell程序都连接到同一服务器和同一数据库,并且正在查询该数据库的同一用户模式。
Un
COMMIT
ted data is only visible within the session that created it (and willROLLBACK
at the end of the session if it has not beenCOMMIT
ted). If you can't see the data from another session (i.e. in SQL*Plus invoked from the shell) then make sure you have issued aCOMMIT
command in the SQL client where youINSERT
ed the data.Note: even if you connect as the same user, this will create a separate session and you will not be able to see the uncommitted data in the other session.
If you have issued a
COMMIT
and still can't see the data then make sure that both the SQL Client and the shell program are connecting to the same server and the same database and are querying the same user's schema of that database.