尝试从.sql脚本创建oracle包时,Flyway解析器失败

时间:2016-09-27 09:18:36

标签: oracle flyway

我有一个存储在.sql文件中的SQL脚本,其中包含多个这样的语句:

create or replace package <schema>.custom_package is 
  procedure getReleaseEmployees(p_Cursor in out sys_refcursor, p_Role in string); 
end custom_package;
/

create or replace package <schema>.pck_account_monitoring is
  procedure checkAndLockOracleAccount;
end pck_account_monitoring;
/
<...some more packages following>

针对我的数据库在SqlDeveloper或PL / SQLDeveloper中运行脚本可以正常工作。 现在,当我尝试使用Java API通过Flyway进行迁移时,我将收到以下错误消息,并且Flyway的迁移失败:

SQL State  : 42000
Error Code : 900
Message    : ORA-00900: Invalid SQL Statement
Location   : migrations/sql/V0_2__migration.sql
Line       : 6172
Statement  : end pck_account_monitoring
    at org.flywaydb.core.internal.dbsupport.SqlScript.execute(SqlScript.java:117)
    at org.flywaydb.core.internal.resolver.sql.SqlMigrationExecutor.execute(SqlMigrationExecutor.java:71)
    at org.flywaydb.core.internal.command.DbMigrate.doMigrate(DbMigrate.java:352)

如果我试图将第一个陈述放在一行中,即

create or replace package quattro.custom_package is procedure getReleaseEmployees(p_Cursor in out sys_refcursor, p_Role in string); end custom_package;
/
<rest as before>

我会收到相同的错误消息,但解析器现在会抱怨'/'符号和下一个语句的开头:

Error Code : 900
Message    : ORA-00900: Invalid SQL Statement
...
Line       : 6167
Statement  : /

create or replace package quattro.pck_account_monitoring is ...

现在,如果我也删除了第一个'/',那么迁移将会运行(尽管有警告)。 然后我的模式将正确地编译除第一个之外的所有其他包 - 即使每个其他包声明的格式都像第一个包在初始尝试中!但是第一个包(custom_package)仍然缺失。

我的Java类基本上看起来像Flyway主页上的示例类。

有没有人知道Flyway解析器出了什么问题,或者可以为我提供一个解决方法?

1 个答案:

答案 0 :(得分:0)

(这对于评论来说太长了,因此,我将其作为答案发布)

FWIW,我无法重现这一点(使用Flyway 3.2.1命令行工具);运行此示例脚本:

-- PACKAGES
create or replace package flyway_demo.custom_package is 
  procedure getReleaseEmployees(p_Cursor in out sys_refcursor, p_Role in string); 
end custom_package;
/

create or replace package flyway_demo.pck_account_monitoring is
  procedure checkAndLockOracleAccount;
end pck_account_monitoring;
/

create or replace package flyway_demo.logger
  authid definer
as
  -- TYPES
  type rec_param is record(
    name varchar2(255),
    val varchar2(4000));

  type tab_param is table of rec_param index by binary_integer;

  g_off constant number := 0;

  function is_number(p_str in varchar2)
      return boolean;
end logger;
/


create or replace package body flyway_demo.pck_account_monitoring is
  procedure checkAndLockOracleAccount is
  begin
    null;
  end;
end pck_account_monitoring;
/

create or replace package body flyway_demo.custom_package is 
  procedure getReleaseEmployees(p_Cursor in out sys_refcursor, p_Role in string)
  is
  begin
    open p_Cursor for select * from dual;
  end;
end custom_package;
/

create or replace package body flyway_demo.logger
as

  function is_number(p_str in varchar2) return boolean is
  begin
    return true;
  end;
end logger;
/

完美无缺。你能用这个脚本试试并发表你的发现吗?