Hsqldb找不到我刚创建的序列

时间:2017-09-08 12:13:28

标签: sql hsqldb

我正在尝试将这个简单的代码用于在DDL SQL脚本中创建序列:

CREATE SEQUENCE seq START WITH 1 INCREMENT BY 1;
INSERT INTO MyTable (id, perc, tablex_id, tabley_id) SELECT NEXT VALUE FOR seq, 0, t.id, cb.id FROM tablex t, tabley cb;

但是我收到了这个错误:

Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: SEQ
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.ParserDQL.readSequenceExpressionOrNull(Unknown Source)
    at org.hsqldb.ParserDQL.XreadSimpleValueExpressionPrimary(Unknown Source)
    at org.hsqldb.ParserDQL.XreadAllTypesValueExpressionPrimary(Unknown Source)
    at org.hsqldb.ParserDQL.XreadAllTypesPrimary(Unknown Source)
    at org.hsqldb.ParserDQL.XreadAllTypesFactor(Unknown Source)
    at org.hsqldb.ParserDQL.XreadAllTypesTerm(Unknown Source)
    at org.hsqldb.ParserDQL.XreadAllTypesCommonValueExpression(Unknown Source)
    at org.hsqldb.ParserDQL.XreadValueExpression(Unknown Source)
    at org.hsqldb.ParserDQL.XreadSelect(Unknown Source)
    at org.hsqldb.ParserDQL.XreadQuerySpecification(Unknown Source)
    at org.hsqldb.ParserDQL.XreadSimpleTable(Unknown Source)
    at org.hsqldb.ParserDQL.XreadQueryPrimary(Unknown Source)
    at org.hsqldb.ParserDQL.XreadQueryTerm(Unknown Source)
    at org.hsqldb.ParserDQL.XreadQueryExpressionBody(Unknown Source)
    at org.hsqldb.ParserDQL.XreadQueryExpression(Unknown Source)
    at org.hsqldb.ParserDML.compileInsertStatement(Unknown Source)
    at org.hsqldb.ParserCommand.compilePart(Unknown Source)
    at org.hsqldb.ParserCommand.compileStatements(Unknown Source)
    at org.hsqldb.Session.executeDirectStatement(Unknown Source)
    at org.hsqldb.Session.execute(Unknown Source)
    ... 31 more

为什么Hqdlb找不到序列seq?我正在使用Hsqldb 2.4.0。

1 个答案:

答案 0 :(得分:1)

您需要逐个执行这些SQL语句。

当多个SQL语句作为一个语句提交给数据库时,HSQLDB会在逐个执行语句之前解析并编译完整的文本。编译第二个语句时,第一个语句尚未执行,此时序列不存在。