Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
319 views
in Technique[技术] by (71.8m points)

java - Syntax error in SQL statement “WITH” keyword throwing exception

I have also added another TMP2 and was not able to run the query... Could you please help me on this query? I am using Oracle 11g.

WITH TMP1(REQUEST_NO) AS (SELECT REQUEST_NO FROM QUOTE) 
SELECT TMP1.REQUEST_NO FROM TMP1;

WITH TMP1(REQUEST_NO) AS
  (SELECT REQUEST_NO FROM QUOTE),
  TMP2(AGENT) AS (SELECT AGENT FROM AGENT_TAB)
SELECT TMP2.AGENT FROM TMP2;

The exception I got is :

org.h2.jdbc.JdbcSQLException:
Syntax error in SQL statement "WITH TMP1(REQUEST_NO) AS (SELECT REQUEST_NO FROM QUOTE),
[*]TMP2(AGENT) AS (SELECT AGENT FROM AGENT_TAB) SELECT TMP2.AGENT FROM TMP2 "; expected "(,
SELECT, FROM"; SQL statement:

The query is fine in sql developer but not working in the Junit tests. jdbc:h2:mem:request_no;MODE=Oracle We are using the h2 version 1.3.171 with windows 7 (64 bit) and jdk 1.7.0_25.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Oracle supports the WITH clause, but it is looks like H2 does not support it: H2 SQL grammar

I would transform the query in the with part to the main query.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...