SQL错误:找不到FROM关键字

时间:2014-12-01 00:36:05

标签: java sql oracle

好的,我收到一个错误:java.sql.SQLException:ORA-00923:在运行此查询时找不到FROM关键字。我不明白我在下面有FROM语句。感谢。

    ResultSet rs = 
stmt.executeQuery("SELECT Airline, 
Avg((extract(day from (Actual_time - Scheduled_time)) * 24 * 60) (extract(hour from (Actual_time - Scheduled_time)) * 60) (extract(minute from (Actual_time - Scheduled_time)))) 
AS 'Average Delay in Minutes' 
FROM Flight Group by Airline");

2 个答案:

答案 0 :(得分:0)

也许格式化代码可以使事情更容易阅读

在字段名称中添加空格是个坏主意

SELECT
    Airline, 
    AVG(
        (EXTRACT(DAY FROM (Actual_time - Scheduled_time)) * 24 * 60)
        (EXTRACT(HOUR FROM (Actual_time - Scheduled_time)) * 60)
        (EXTRACT(MINUTE FROM (Actual_time - Scheduled_time)))
    ) AS Average_delay_in_minutes 
FROM Flight
GROUP BY Airline;

答案 1 :(得分:0)

我不确定为什么你有像(day)(hour)(minute)这样的逻辑。据推测,您希望组件之间有+

SELECT Airline, 
       Avg((extract(day from (Actual_time - Scheduled_time)) * 24 * 60) +
           (extract(hour from (Actual_time - Scheduled_time)) * 60) +
           (extract(minute from (Actual_time - Scheduled_time)))
          ) AS AverageDelayInMinutes
FROM Flight
Group by Airline;

您的括号似乎在原始查询中保持平衡,因此我怀疑问题是缺少运算符。