H2 DB交叉连接未执行

时间:2016-02-01 11:31:57

标签: java sql h2

我正在使用H2-1.4.191.jar DB并拥有此SQL:

org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement " SELECT * FROM ( (SELECT A.COL AS AC_1, B.COL AS BC_1 FROM A, B WHERE AC_1 = 'some_const') CROSS[*] JOIN (SELECT A.COL AS AC_2, B.COL AS BC_2 FROM A, B WHERE AC_2 = 'some_another_const')) WHERE BC_1 <> BC_2 LIMIT 1"; expected "UNION, MINUS, EXCEPT, INTERSECT, ORDER, OFFSET, FETCH, LIMIT, FOR, )";
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.getSyntaxError(DbException.java:205)
at org.h2.command.Parser.getSyntaxError(Parser.java:535)
at org.h2.command.Parser.read(Parser.java:3170)
at org.h2.command.Parser.readTableFilter(Parser.java:1170)
at org.h2.command.Parser.parseSelectSimpleFromPart(Parser.java:1884)
at org.h2.command.Parser.parseSelectSimple(Parser.java:2032)
at org.h2.command.Parser.parseSelectSub(Parser.java:1878)
at org.h2.command.Parser.parseSelectUnion(Parser.java:1699)
at org.h2.command.Parser.parseSelect(Parser.java:1687)
at org.h2.command.Parser.parsePrepared(Parser.java:443)
at org.h2.command.Parser.parse(Parser.java:315)
at org.h2.command.Parser.parse(Parser.java:291)
at org.h2.command.Parser.prepareCommand(Parser.java:252)
at org.h2.engine.Session.prepareLocal(Session.java:560)
at org.h2.engine.Session.prepareCommand(Session.java:501)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1188)
at org.h2.jdbc.JdbcStatement.executeQuery(JdbcStatement.java:73)
at generation.db.QueryMaker.exec(QueryMaker.java:139)

H2DB放在内存中,并嵌入在我的Java App中。当我尝试执行SQL时,我得到以下异常:

package

在SQLite中一切正常。 我该怎么办才能让它在H2中运作?

1 个答案:

答案 0 :(得分:0)

没有外括号的此查询可以正常工作:

  SELECT * FROM (SELECT A.COL AS AC_1, B.COL AS BC_1 FROM A, B WHERE AC_1 = 'someconst') CROSS JOIN (SELECT A.COL AS AC_2, B.COL AS BC_2 FROM A, B WHERE AC_2 = 'another_const') WHERE BC_1 <> BC_2 LIMIT 1