运行liquibase脚本时无效的字符

时间:2013-11-14 08:33:09

标签: sql oracle liquibase

当我在Sql Developer中运行下面的脚本时,它正确地创建了我的全局临时表,但是当我运行liquibase脚本时,由于“无效字符”而失败。有人知道为什么会失败吗?

在Sql Developer中(工作)

 CREATE GLOBAL TEMPORARY TABLE TransactionsToMove(
              TransactionId NUMBER(38,0) NOT NULL,
              PRIMARY KEY (TransactionId))
              ON COMMIT DELETE ROWS;

Liquibase xml (以下堆栈跟踪失败)

<changeSet id="createGlobalTemporaryTableForTransactionsMove" author="me" >
    <preConditions onFail="MARK_RAN">
        <not>
            <tableExists tableName="TransactionsToMove"/>
        </not>
    </preConditions>
    <sql splitStatements="false" endDelimiter=";"><![CDATA[              
      CREATE GLOBAL TEMPORARY TABLE TransactionsToMove(
          TransactionId NUMBER(38,0) NOT NULL,
          PRIMARY KEY (TransactionId))
          ON COMMIT DELETE ROWS;
    ]]>
    </sql>
</changeSet>

堆栈跟踪

    SEVERE 2013-11-14 09:10:liquibase: Error executing SQL CREATE GLOBAL TEMPORARY TABLE TransactionsToMove(
              TransactionId NUMBER(38,0) NOT NULL,
              PRIMARY KEY (TransactionId))
              ON COMMIT DELETE ROWS;
java.sql.SQLSyntaxErrorException: ORA-00911: invalid character

        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 liquibase.executor.jvm.JdbcExecutor$1ExecuteStatementCallback.doInStatement(JdbcExecutor.java:92)
        at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:55)
        at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:105)
        at liquibase.database.AbstractDatabase.execute(AbstractDatabase.java:1014)
        at liquibase.database.AbstractDatabase.executeStatements(AbstractDatabase.java:998)
        at liquibase.changelog.ChangeSet.execute(ChangeSet.java:317)
        at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:27)
        at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:58)
        at liquibase.Liquibase.update(Liquibase.java:113)
        at se.mypackage.exbo.database.liquibase.LiquibaseDatabaseManager.runChangelog(LiquibaseDatabaseManager.java:177)
        at se.mypackage.exbo.database.liquibase.LiquibaseDatabaseManager.create(LiquibaseDatabaseManager.java:145)
        at se.mypackage.exbo.database.DatabaseManager.dropAndCreate(DatabaseManager.java:349)
        at se.mypackage.exbo.database.DatabaseManager.main(DatabaseManager.java:720)
SEVERE 2013-11-14 09:10:liquibase: Change Set db/scripts/movetohistorical-oracleserver.xml::createGlobalTemporaryTableForTransactionsMove::marbe failed.  Error: Error executing SQL CREATE GLOBAL TEMPORARY TABLE TransactionsToMove(
              TransactionId NUMBER(38,0) NOT NULL,
              PRIMARY KEY (TransactionId))
              ON COMMIT DELETE ROWS;: ORA-00911: invalid character

liquibase.exception.DatabaseException: Error executing SQL CREATE GLOBAL TEMPORARY TABLE TransactionsToMove(
              TransactionId NUMBER(38,0) NOT NULL,
              PRIMARY KEY (TransactionId))
              ON COMMIT DELETE ROWS;: ORA-00911: invalid character

        at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:62)
        at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:105)
        at liquibase.database.AbstractDatabase.execute(AbstractDatabase.java:1014)
        at liquibase.database.AbstractDatabase.executeStatements(AbstractDatabase.java:998)
        at liquibase.changelog.ChangeSet.execute(ChangeSet.java:317)
        at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:27)
        at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:58)
        at liquibase.Liquibase.update(Liquibase.java:113)
        at se.mypackage.exbo.database.liquibase.LiquibaseDatabaseManager.runChangelog(LiquibaseDatabaseManager.java:177)
        at se.mypackage.exbo.database.liquibase.LiquibaseDatabaseManager.create(LiquibaseDatabaseManager.java:145)
        at se.mypackage.exbo.database.DatabaseManager.dropAndCreate(DatabaseManager.java:349)
        at se.mypackage.exbo.database.DatabaseManager.main(DatabaseManager.java:720)
Caused by: java.sql.SQLSyntaxErrorException: ORA-00911: invalid character

        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 liquibase.executor.jvm.JdbcExecutor$1ExecuteStatementCallback.doInStatement(JdbcExecutor.java:92)
        at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:55)
        ... 11 more
INFO 2013-11-14 09:10:liquibase: Successfully released change log lock
Exception in thread "main" se.mypackage.exbo.database.DatabaseManagerException: Liquibase changelog update failed using changelog: db-main-create-13.4.xml, reason: Migration failed for change set db/scripts/movetohistorical-oraclese
     Reason: liquibase.exception.DatabaseException: Error executing SQL CREATE GLOBAL TEMPORARY TABLE TransactionsToMove(
              TransactionId NUMBER(38,0) NOT NULL,
              PRIMARY KEY (TransactionId))
              ON COMMIT DELETE ROWS;: ORA-00911: invalid character
:
          Caused By: Error executing SQL CREATE GLOBAL TEMPORARY TABLE TransactionsToMove(
              TransactionId NUMBER(38,0) NOT NULL,
              PRIMARY KEY (TransactionId))
              ON COMMIT DELETE ROWS;: ORA-00911: invalid character
:
          Caused By: ORA-00911: invalid character

        at se.mypackage.exbo.database.liquibase.LiquibaseDatabaseManager.runChangelog(LiquibaseDatabaseManager.java:180)
        at se.mypackage.exbo.database.liquibase.LiquibaseDatabaseManager.create(LiquibaseDatabaseManager.java:145)
        at se.mypackage.exbo.database.DatabaseManager.dropAndCreate(DatabaseManager.java:349)
        at se.mypackage.exbo.database.DatabaseManager.main(DatabaseManager.java:720)
Caused by: liquibase.exception.MigrationFailedException: Migration failed for change set db/scripts/movetohistorical-oracleserver.xml::createGlobalTemporaryTableForTransactionsMove::marbe:
     Reason: liquibase.exception.DatabaseException: Error executing SQL CREATE GLOBAL TEMPORARY TABLE TransactionsToMove(
              TransactionId NUMBER(38,0) NOT NULL,
              PRIMARY KEY (TransactionId))
              ON COMMIT DELETE ROWS;: ORA-00911: invalid character
:
          Caused By: Error executing SQL CREATE GLOBAL TEMPORARY TABLE TransactionsToMove(
              TransactionId NUMBER(38,0) NOT NULL,
              PRIMARY KEY (TransactionId))
              ON COMMIT DELETE ROWS;: ORA-00911: invalid character
:
          Caused By: ORA-00911: invalid character

        at liquibase.changelog.ChangeSet.execute(ChangeSet.java:347)
        at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:27)
        at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:58)
        at liquibase.Liquibase.update(Liquibase.java:113)
        at se.mypackage.exbo.database.liquibase.LiquibaseDatabaseManager.runChangelog(LiquibaseDatabaseManager.java:177)
        ... 3 more
Caused by: liquibase.exception.DatabaseException: Error executing SQL CREATE GLOBAL TEMPORARY TABLE TransactionsToMove(
              TransactionId NUMBER(38,0) NOT NULL,
              PRIMARY KEY (TransactionId))
              ON COMMIT DELETE ROWS;: ORA-00911: invalid character

        at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:62)
        at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:105)
        at liquibase.database.AbstractDatabase.execute(AbstractDatabase.java:1014)
        at liquibase.database.AbstractDatabase.executeStatements(AbstractDatabase.java:998)
        at liquibase.changelog.ChangeSet.execute(ChangeSet.java:317)
        ... 7 more
Caused by: java.sql.SQLSyntaxErrorException: ORA-00911: invalid character

        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 liquibase.executor.jvm.JdbcExecutor$1ExecuteStatementCallback.doInStatement(JdbcExecutor.java:92)
        at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:55)
        ... 11 more

2 个答案:

答案 0 :(得分:10)

分号是客户端应用程序(如Oracle SQL * Plus)中使用的命令终止符。

通过Prepared Statement或类似技术调用db命令时通常不需要。

答案 1 :(得分:0)

很明显:从Liquibase中删除SEMICOLONS

Liquibase无法正确容忍分号。 SQL Developer希望您使用分号。 将陈述从一个粘贴到另一个粘贴会使您陷入麻烦。

可以在网上找到一些解释的尝试,例如: http://forum.liquibase.org/topic/formatted-sql-enddelimiter-issue

值得注意的是,Oracle本身对分号有不同的处理方式:SQL * Plus命令不需要以分号结尾;而声明应该这样做。