我们在Liquibase 3.6.1命令行上有一个简单的创建视图测试用例:
我们正在努力了解如何解决错误:
ORA-00933:SQL命令未正确结束
我们已经尝试了
<sql>
<createview>
以下是一个简单的测试用例。
以下是更改日志:
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet author="jim" id="test1">
<createView viewName="VIEW_TEST" replaceIfExists="true" >
select table_name FROM user_tables ORDER BY table_name;
</createView>
</changeSet>
</databaseChangeLog>
命令
time ./liquibase --changeLogFile=../changelog/test.xml --url=jdbc:oracle:thin:@//localhost:1521/ORCL --username "sys as sysdba" --password oracle --logLevel debug update
我们总是得到这个例外:(仅供参考我们也尝试<sql>
相同的结果)
➜ liquibase-3.6.1 time ./liquibase --changeLogFile=../changelog/test.xml --url=jdbc:oracle:thin:@//localhost:1521/ORCL --username "sys as sysdba" --password oracle --logLevel debug update
Starting Liquibase at Mon, 04 Jun 2018 12:52:44 PDT (version 3.6.1 built at 2018-04-11 08:41:04)
**Unexpected error running Liquibase: ORA-00933: SQL command not properly ended**
[Failed SQL: CREATE OR REPLACE VIEW SYS.VIEW_TEST AS select table_name FROM user_tables ORDER BY table_name;]
liquibase.exception.MigrationFailedException: Migration failed for change set ../changelog/test.xml::test1::jim:
Reason: liquibase.exception.DatabaseException: ORA-00933: SQL command not properly ended
**[Failed SQL: CREATE OR REPLACE VIEW SYS.VIEW_TEST AS select table_name FROM user_tables ORDER BY table_name;]**
at liquibase.changelog.ChangeSet.execute(ChangeSet.java:637)
at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:53)
at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:78)
at liquibase.Liquibase.update(Liquibase.java:202)
at liquibase.Liquibase.update(Liquibase.java:179)
at liquibase.integration.commandline.Main.doMigration(Main.java:1205)
at liquibase.integration.commandline.Main.run(Main.java:191)
at liquibase.integration.commandline.Main.main(Main.java:129)
Caused by: liquibase.exception.DatabaseException: ORA-00933: SQL command not properly ended
[Failed SQL: CREATE OR REPLACE VIEW SYS.VIEW_TEST AS select table_name FROM user_tables ORDER BY table_name;]
at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:356)
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:57)
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:125)
at liquibase.database.AbstractJdbcDatabase.execute(AbstractJdbcDatabase.java:1229)
at liquibase.database.AbstractJdbcDatabase.executeStatements(AbstractJdbcDatabase.java:1211)
at liquibase.changelog.ChangeSet.execute(ChangeSet.java:600)
... 7 common frames omitted
**Caused by: java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended**
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1017)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:655)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:249)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:566)
at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:202)
at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:45)
at oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:933)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1075)
at oracle.jdbc.driver.OracleStatement.executeInternal(OracleStatement.java:1718)
at oracle.jdbc.driver.OracleStatement.execute(OracleStatement.java:1678)
at oracle.jdbc.driver.OracleStatementWrapper.execute(OracleStatementWrapper.java:332)
at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:352)
... 12 common frames omitted
For more information, please use the --logLevel flag
./liquibase --changeLogFile=../changelog/test.xml --username "sys as sysdba" 4.61s user 0.27s system 238% cpu 2.048 total
答案 0 :(得分:1)
您的日志显示您正在尝试在SYS架构中创建视图。这是不允许的。
为您的应用程序创建(如果尚未创建)架构。与COOL_APP一样。
在XML中使用此架构。像COOL_APP.VIEW_TEST。
答案 1 :(得分:1)
你的sql语句是否正确?
<changeSet author="jim" id="test1">
<createView
replaceIfExists="true"
viewName="VIEW_TEST">
select * FROM table_name ORDER BY table_column;
</createView>
</changeSet>
答案 2 :(得分:1)
解决方案是删除视图末尾的分号,这样可以正常工作: