Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
303 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...