H2'AS'列别名错误

时间:2015-08-03 20:17:07

标签: sql oracle h2

所以这是H2表架构:

drop table IF EXISTS

CREATE TABLE CAR_SPEED
(
  ACC_RATE                      VARCHAR2(20) NOT NULL,
  SPEED_GROUP                   VARCHAR2(30) NOT NULL,
  MAX_SPEED                     NUMBER,
  MIN_SPEED                     NUMBER       
);

我试图执行的查询语句是:

SELECT distinct MAX_SPEED as limit
FROM CAR_SPEED  
WHERE ACC_RATE ='Full' 
AND SPEED_GROUP = 'CS';

当我在oracle中运行这个完全相同的查询时我没有问题但是当我在h2上运行时出现以下错误

Caused by: org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "SELECT DISTINCT MAX_SPEED AS LIMIT[*]
FROM CAR_SPEED 
WHERE CAR_SPEED 
AND SPEED_GROUP = 'CS' "; expected "identifier"; SQL statement:
SELECT DISTINCT MAX_SPEED AS LIMIT[*]
FROM CAR_SPEED 
WHERE CAR_SPEED 
AND SPEED_GROUP = 'CS' [42001-160]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)

如果我从查询中删除“AS LIMIT”它将运行正常,但是当我保留它时,它会给我这个语法错误。有谁知道为什么?

1 个答案:

答案 0 :(得分:2)

limitreserved word。使用另一个或用双引号将其转义。