我必须运行目录中的所有sql文件。所以,使用for循环,我能够实现这一点,但是现在构建正在获得成功,即使任何sql都失败了。
如果任何sql在循环中执行失败,如何使ant构建失败?
编译文件
<?xml version="1.0"?>
<project name="run_build" default="full_build">
<target name="init" description="Initialize the Ant variables">
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
</target>
<target name="run_sqls" depends="init" description="Run SQLs">
<for param="sqlfile">
<path>
<fileset dir="." includes="*.sql"/>
</path>
<sequential>
<property name="sqlfilename" value="@{sqlfile}"/>
<echo message = "Running SQL file : ${sqlfilename} "/>
<exec executable="${ORACLE_HOME}/bin/sqlplus" failonerror="true">
<arg value="dbuser/dbpass@dbinstance"/>
<arg value="@${sqlfilename}"/>
</exec>
</sequential>
</for>
</target>
<target name="full_build" description="Running full build">
<antcall target="run_sqls"/>
</target>
</project>
当前输出:即使sql失败,生成也成功。
Buildfile: build.xml
full_build:
init:
run_sqls:
[echo] Running Schema SQL file : abc.sql
[exec]
[exec] SQL*Plus: Release 11.2.0.3.0 Production on Wed Aug 5 14:20:25 2020
[exec]
[exec] Copyright (c) 1982, 2011, Oracle. All rights reserved.
[exec]
[exec]
[exec] Connected to:
[exec] Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
[exec] With the Partitioning, OLAP, Data Mining and Real Application Testing options
[exec]
[exec] update table_sdj set first_name='FirstName' where id=123
[exec] *
[exec] ERROR at line 1:
[exec] ORA-00942: table or view does not exist
[exec]
[exec]
[exec]
[exec] Commit complete.
[exec]
[exec] SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
[exec] With the Partitioning, OLAP, Data Mining and Real Application Testing options
BUILD SUCCESSFUL
Total time: 0 seconds
1条答案
按热度按时间w9apscun1#
您必须将这些子句添加到sqlplus脚本中,以控制是否存在sql错误或os错误。
然后,必须控制程序中的返回代码,以验证脚本是否正常执行。否则,不管发生什么,sqlplus总是以0退出。
例子
包括正确的条款
默认情况下,如图所示,sqlplus总是以0退出。当错误发生时,您需要指示它带着错误退出。
每当sqlerror