通过Ant执行SQL脚本

时间:2014-11-07 09:17:27

标签: oracle ant

我有一个工作的SQL脚本,.sql文件用于Oracle,当我从SQL Developer执行时工作正常,但现在我试图从ANT脚本中调用它,这会给我带来很多与语法有关的错误。< / p>

当我的目标是通过ant执行sql脚本时,任何人都可以帮助我吗?

EG。来自.sql文件的下面的语句在SQL Developer中工作得非常好,但Ant却抛出了语法错误。

myuser@myserver:/app/myapp/myAnt/install $ ant TestSQL
Buildfile: /app/myapp/myAnt/install/build.xml

TestSQL:
      [sql] Executing resource: /app/myapp/myAnt/install/config/SQL/CleanDB.sql
      [sql] Failed to execute:  SET SERVEROUTPUT ON

BUILD FAILED
/app/myapp/myAnt/install/build.xml:32: java.sql.SQLSyntaxErrorException: ORA-00922: Fehlende oder ungültige Option
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
    at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879)
    at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:450)
    at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192)
    at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
    at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:193)
    at oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:1033)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1329)
    at oracle.jdbc.driver.OracleStatement.executeInternal(OracleStatement.java:1909)
    at oracle.jdbc.driver.OracleStatement.execute(OracleStatement.java:1871)
    at oracle.jdbc.driver.OracleStatementWrapper.execute(OracleStatementWrapper.java:318)
    at org.apache.tools.ant.taskdefs.SQLExec.execSQL(SQLExec.java:775)
    at org.apache.tools.ant.taskdefs.SQLExec.runStatements(SQLExec.java:745)
    at org.apache.tools.ant.taskdefs.SQLExec$Transaction.runTransaction(SQLExec.java:1055)
    at org.apache.tools.ant.taskdefs.SQLExec$Transaction.access$000(SQLExec.java:985)
    at org.apache.tools.ant.taskdefs.SQLExec.execute(SQLExec.java:653)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:392)
    at org.apache.tools.ant.Target.performTasks(Target.java:413)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    at org.apache.tools.ant.Main.runBuild(Main.java:811)
    at org.apache.tools.ant.Main.startAnt(Main.java:217)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

总时间:1秒

2 个答案:

答案 0 :(得分:0)

我的理解是set SERVEROUTPUT ON是SQL * Plus命令而不是SQL语句,并且Ant sql任务使用的JDBC驱动程序不理解它。

相反,您可能需要使用exec任务从Ant调用PL / SQL,类似于:

<exec executable="${oracle.bin.dir}/sqlplus" failonerror="true">
  <arg value="${username}/${password}@${tns_alias}"/>
  <arg value="@${script.path}/my_script.sql"/>
</exec>

答案 1 :(得分:0)

您的SQL脚本未添加,但我认为使用分隔符 delimitertype 属性可能会有所帮助here

不确定上面提到的 exec 任务,因为它不是通用解决方案(我建议尽可能使用SQL Ant任务来支持不同的数据库提供程序)。

古德勒克