ANT SQL任务:如何运行SQL和PL / SQL,并注意执行失败? [英] ANT sql task: How to run SQL and PL/SQL and notice execution failure?

查看:245
本文介绍了ANT SQL任务:如何运行SQL和PL / SQL,并注意执行失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行从ANT一个.SQL脚本文件,它使用以下任务正常工作:

to execute an .sql script file from ANT it works fine using the following task:

<sql
    classpath="${oracle.jar}" driver="oracle.jdbc.OracleDriver"
    url="jdbc:oracle:thin:@@@{db.hostname}:@{db.port}:@{db.sid}" 
    userid="@{db.user}" 
    password="@{db.password}"
    src="@{db.sql.script}" />

但如果.sql文件不仅包含纯SQL也是PL / SQL的任务将失败。这可以通过使用下面的代码片段来解决:

But if the .sql file not only contains pure SQL but also PL/SQL the task will fail. This could be solved by using the following snippet:

<sql
    classpath="${oracle.jar}" driver="oracle.jdbc.OracleDriver"
    url="jdbc:oracle:thin:@@@{db.hostname}:@{db.port}:@{db.sid}" 
    userid="@{db.user}" 
    password="@{db.password}"
    delimiter="/"
    delimitertype="row"
    src="@{db.sql.script}" />

但是,如果我的脚本包含SQL PL / SQL则两个Ant任务会工作。另一种解决方案是使用了执行任务与sqlplus的

But if my script contains both SQL and PL/SQL then neither ANT task will work. Another solution would be to use the "exec" task with "sqlplus":

<exec executable="sqlplus" failonerror="true" errorproperty="exit.status">
    <arg value="${db.user}/${db.password}@${db.hostname}:${db.port}/${db.sid}"/>
    <arg value="@${db.sql.script}"/>
</exec>

不过遗憾的是这个任务永远不会失败,因此,构建以成功总是返回,即使SQL脚本执行失败。我试图设置不会返回任何错误code error属性。

But unfortunately this task will never fail, hence the build returns always with "SUCCESSFUL" even though the sql script execution failed. The error property which I tried to set would not return any error code.

任何意见/建议,如何解决这个问题?

Any ideas/suggestions how to solve this problem?

谢谢,

彼得

推荐答案

彼得,

在添加脚本的开头

  WHENEVER SQLERROR EXIT SQL.CODE;

然后sqlplus中退出,退出code!= 0。

Then sqlplus will exit with exit code != 0.

这篇关于ANT SQL任务:如何运行SQL和PL / SQL,并注意执行失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆