使用liquibase在一个sqlFile中使用PL / SQL和SQL脚本?

时间:2015-08-19 15:21:34

标签: sql oracle jenkins plsql liquibase

我尝试在房间changeSet / sqlFile中运行很多选项,其中包含pl / sql块和simlple sql语句。 E.g:

BEGIN
    aud.someProcedure('parameter');
END;
/
insert into test_table(_id, value) VALUES(1, 'test');

但我得到以下例外:

liquibase.exception.MigrationFailedException: Migration failed for change set [xml path]:
     Reason: liquibase.exception.DatabaseException: ORA-06550: 4 line, 1 col:
PLS-00103: Encountered the symbol: "/" 
 [Failed SQL: BEGIN 
    aud.someProcedure('parameter'); 
END; 
//
insert into test_table(_id, value) VALUES(1, 'test')
]
    at liquibase.changelog.ChangeSet.execute(ChangeSet.java:584)
    at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:51)
    at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:73)
    at liquibase.Liquibase.update(Liquibase.java:210)
    at liquibase.Liquibase.update(Liquibase.java:190)
    at liquibase.Liquibase.update(Liquibase.java:186)
    at org.jenkinsci.plugins.liquibase.builder.LiquibaseBuilder.perform(LiquibaseBuilder.java:128)
    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
    at hudson.model.Build$BuildExecution.build(Build.java:205)
    at hudson.model.Build$BuildExecution.doRun(Build.java:162)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:537)
    at hudson.model.Run.execute(Run.java:1741)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:98)
    at hudson.model.Executor.run(Executor.java:381)
Caused by: liquibase.exception.DatabaseException: ORA-06550: 4 line, col oszlop:
PLS-00103: Encountered the symbol: "/" 
 [Failed SQL: BEGIN 
    aud.someProcedure('parameter'); 
END; 
//
insert into test_table(_id, value) VALUES(1, 'test')
]

当我尝试在xml中更改splitStatement和endDelimiter时,没有任何改变。

你有想法吗?

2 个答案:

答案 0 :(得分:6)

" endDelimiter"效果很好。

SQL语句中的分号会产生"无效的字符错误",所以当它不是分隔符时你必须删除它。 (是的,它在PL / SQL和SQL * Plus中工作,就像斜杠" /",更多:When do I need to use a semicolon vs a slash in Oracle SQL?

解决方案:

  • endDelimiter =" /"

    <changeSet id="1" author="me">
    <sql endDelimiter="/">
        BEGIN
            aud.someProcedure('parameter');
        END;
        /
        insert into test_table(_id, value) VALUES(1, 'test')
    </sql>
    </changeSet>
    
  • 两个部分

    <changeSet id="1" author="me">
    <sql endDelimiter="/">
        BEGIN
            aud.someProcedure('parameter');
        END;
    </sql>
    <sql>
        insert into test_table(_id, value) VALUES(1, 'test');
    </sql>
    </changeSet>
    
  • 或者也许;)

    <changeSet id="1" author="me">
    <sql endDelimiter="#Gabor was here#">
        BEGIN
            aud.someProcedure('parameter');
        END;
        #Gabor was here#
        insert into test_table(_id, value) VALUES(1, 'test')
    </sql>
    </changeSet>
    

答案 1 :(得分:1)

尝试将insert语句放在Begin,end块中,并可能删除尾部斜杠(/)字符:

class ASomething
    : public virtual ISomething
{
public:
  virtual int f(int x, int y) // (2)
  {
    return f(x) + f(y); // (3)
  }

  using ISomething::f;
  //~~~~~~~~~~~~~~~~~^
};

class SomethingImpl
   : public ASomething
{
public:
  virtual int f(int x) // (1)
  {
    return x+1;
  }    

  using ASomething::f;
  //~~~~~~~~~~~~~~~~~^
};

斜杠是SQL * Plus使用的终止字符,以及一些用于表示PL / SQL块结束的交互式查询工具。