加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl – 如何在使用open / print执行SQL语句时捕获退出代码?

发布时间:2020-12-15 21:46:54 所属栏目:大数据 来源:网络整理
导读:我使用open / print来使用sqlplus执行SQL语句,如下所示: open (PLSQL,"|sqlplus -s $db_url");print PLSQL ENDSQL;... some SQL statements ...exit;ENDSQLclose(PLSQL); 我的问题是如果遇到一些错误,如何捕获执行sql语句的退出代码.我认为使用DBI会好得多,
我使用open / print来使用sqlplus执行SQL语句,如下所示:
open (PLSQL,"|sqlplus -s $db_url");
print PLSQL <<ENDSQL;
... some SQL statements ...
exit;
ENDSQL
close(PLSQL);

我的问题是如果遇到一些错误,如何捕获执行sql语句的退出代码.我认为使用DBI会好得多,但我更愿意找到解决上述问题的方法.非常感谢!

解决方法

close()应该告诉你你想知道什么:

If the filehandle came from a piped open,close returns false if one of the other syscalls involved fails or if its program exits with non-zero status. If the only problem was that the program exited non-zero,$! will be set to 0 . Closing a pipe also waits for the process executing on the pipe to exit–in case you wish to look at the output of the pipe afterwards–and implicitly puts the exit status value of that command into $? and ${^CHILD_ERROR_NATIVE}.

要点是close()将为任何错误返回false,$!只有在系统调用有错误时才会设置,并且$?将被设置为退出状态.有关详情,请参阅Error Variables in perlvar.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读