2

Following is a trigger:

CREATE OR REPLACE TRIGGER "CMDC"."USER_ROADS_UC"
BEFORE INSERT OR UPDATE OF
    ASSOCIATED_PARENT_ROAD
ON USER_ROADS
REFERENCES NEW AS NEW
FOR EACH ROW BEGIN
    :new.ASSOCIATED_PARENT_ROAD:=upper(:new.ASSOCIATED_PARENT_ROAD);
    EXCEPTION
    WHEN OTHERS THEN RETURN;
END;
/
ALTER TRIGGER "CMDC"."USER_ROADS_UC" ENABLE

The above runs perfectly in SQL Developer. However, when I get the following error when I run it using Ant:

[sql] Failed to execute:  EXCEPTION WHEN OTHERS THEN RETURN
[sql] java.sql.SQLException: ORA-00900: invalid SQL statement
[sql] Failed to execute:  END
[sql] java.sql.SQLException: ORA-00900: invalid SQL statement
[sql] Failed to execute:  / ALTER TRIGGER "CMDC"."USER_ROADS_UC" ENABLE
[sql] java.sql.SQLException: ORA-00900: invalid SQL statement

I have already reviewed this question. However, I still couldn't modify the script to work with Ant.

Following is the ant target

<target name="create-db-schema" >
        <echo message="############################################################"/>
        <echo message="#               Create Complete DB Schema                  #"/>
        <echo message="############################################################"/>

        <sql onerror="continue" classpathref="project.class.path" driver="${database.driverClassName}"
             url="${database.url}" userid="${database.username}" password="${database.password}">
            <path>
                <fileset dir="${test.dbscripts.dir}/schema/">
                    <include name="*.sql"/>
                </fileset>
            </path>
        </sql>
</target>
7
  • Any difference if you put a semi-colon and/or a / at the conclusion of the ALTER TRIGGER statement? How about if you remove the ALTER TRIGGER statement and put it through as a separate statement in a new call? Commented Jun 22, 2016 at 15:11
  • 1
    But how did you defined your ant task? Did you set up delimiter, delimitertype row? check this Commented Jun 22, 2016 at 15:12
  • @ArkadiuszŁukasiewicz, would you mind showing the relevant build script? Did you try -debug option? Commented Jun 23, 2016 at 14:41
  • Looks you are executing pl/sql and sql together and this might help Commented Jun 23, 2016 at 14:48
  • @Rao I've tried it with adding the delimiter to <sql> but still gives the same error :( Commented Jun 24, 2016 at 5:42

2 Answers 2

0

With ant sql tag I couldn't run both SQL and PL/SQL in the same script even though I tried in many ways.

But using an external library I could do this.I've used this library to do that dbmaintain Add following to your build script.

<path id="dbmaintain-lib"><fileset dir="${dbmaintain.home}/lib"><include name="*.jar"/></fileset></path>
<taskdef resource="dbmaintain-anttasks.xml" classpathref="dbmaintain.lib"/>

    <target name="update-db">
    <updateDatabase scriptLocations="scripts" autoCreateDbMaintainScriptsTable="true">
        <database driverClassName="oracle.jdbc.driver.OracleDriver" userName="user" password="pass" url="jdbc:oracle:thin:@//localhost:1521/XE" schemaNames="SCHEMA"/>
    </updateDatabase>
</target>

And everthing works perfectly now without changes to sql scripts files to replace ';'. Hope this'll help for somebody in need.

Sign up to request clarification or add additional context in comments.

Comments

0

I don't have environment to test this solution. But for testing purpose you can try something like this.

<sql
    driver="xxx"
    url="xxx"
    userid="xxx"
    password="xxx"
    delimiter="/"
    delimitertype="row"
    ><![CDATA[

CREATE OR REPLACE TRIGGER "CMDC"."USER_ROADS_UC"
BEFORE INSERT OR UPDATE OF
    ASSOCIATED_PARENT_ROAD
ON USER_ROADS
REFERENCES NEW AS NEW
FOR EACH ROW BEGIN
    :new.ASSOCIATED_PARENT_ROAD:=upper(:new.ASSOCIATED_PARENT_ROAD);
    EXCEPTION
    WHEN OTHERS THEN RETURN;
END;
/
ALTER TRIGGER "CMDC"."USER_ROADS_UC" ENABLE
/

]]></sql>
  • Important ! Your delimiter now is "/" in new line without any surrounding whitespaces.

1 Comment

Already did this but i kept the sql part in a separate file. It didn't work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.