我有一个如下所示的触发器
create or replace trigger departments_bi before insert on departments_test
for each row
when (new.id is null)
begin
select departments_seq.nextval into :new.id from dual;
end;
/
我指的是使用sqlfile
在changeset xml中的这个触发器<?xml version="1.0" encoding="UTF-8" ?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<changeSet author="raghav" id="004" runOnChange="true">
<sqlFile dbms="oracle"
encoding="ASCII"
endDelimiter="\n"
path="Triggers.sql"
relativeToChangelogFile="true"
splitStatements="false"
stripComments="false"/>
<rollback>
drop trigger departments_bi
</rollback>
</changeSet>
</databaseChangeLog>
使用Ant UpdateDatabase命令生成包含所有更改的SQL文件。我还使用exec任务来执行生成的SQL以及针对目标DB的所有更改。
<updateDatabase
changeLogFile="${checkout}/Trigger.xml"
driver="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@${machineId}:${targetDB_Port}:${targetDB}"
username="${targetDB_User}"
password="${targetDB_Password}"
classpathref="classpath"
outputFile="${env1.WORKSPACE}/Update_MNT.sql"
/>
<echo message="Beginning to execute Update_MNT.sql to target DB ${targetDB} using username ${targetDB_user}"/>
<exec dir="${env1.WORKSPACE}" executable="sqlplus" failonerror="true">
<arg value="${targetDB_User}/${targetDB_Password}@${tnstargetDB}"/>
<arg value="@Update_MNT.sql"/>
</exec>
我遇到的问题是生成的SQL文件。它包含了额外的Trigger.sql文件的内容;最后..所以在使用exec命令执行Update_MNT.sql时。 sqlplus由于额外的原因而失败;在生成的SQL文件中/之后。如何解决这个问题?
-- Changeset E:/Jenkins_Liquibase_Test/Triggers.xml::004::raghav
create or replace trigger departments_bi before insert on departments_test
for each row
when (new.id is null)
begin
select departments_seq.nextval into :new.id from dual;
end;
/;