SQL错误:缺少关键字?

时间:2015-06-19 15:13:58

标签: sql oracle oracle-apex

我在这里收到一个丢失的关键字错误。我最近添加了WHERE子句,那是在缺少关键字错误时出现的。

 Select job_id,
        (Case :P1_DATE_CHOOSER 
             WHEN 'Daily' THEN trunc(start_time)
             WHEN 'Weekly' THEN trunc(start_time, 'WW')
             WHEN 'Monthly' THEN trunc(start_time, 'MM') 
        END) "START_DATE",  
        1440*(END_TIME - START_TIME) "RUN_TIME"
 from NI_INFA_ACTIVITY_LOG_V


WHERE 


 (Case :P1_JOB_SIZE_CHOOSER
 WHEN 'Small' THEN (1440*(END_TIME - START_TIME)) <= 5
 WHEN 'Medium' THEN  (1440*(END_TIME - START_TIME)) > 5 AND 
                (1440*(END_TIME - START_TIME)) <= 20
 WHEN 'Large' THEN (1440*(END_TIME - START_TIME)) > 20
 Else (1440*(END_TIME - START_TIME)) > 0 
 END)

任何帮助都将不胜感激。

2 个答案:

答案 0 :(得分:1)

以这种方式做到:

....
....
WHERE 
:P1_JOB_SIZE_CHOOSER = 'Small' AND (1440*(END_TIME - START_TIME)) <= 5
OR
:P1_JOB_SIZE_CHOOSER = 'Medium' AND (1440*(END_TIME - START_TIME)) > 5 AND 
                (1440*(END_TIME - START_TIME)) <= 20
OR
:P1_JOB_SIZE_CHOOSER = 'Large' AND ((1440*(END_TIME - START_TIME)) > 20
OR
:P1_JOB_SIZE_CHOOSER NOT IN('Small','Medium','Large') AND (1440*(END_TIME - START_TIME)) > 0 

答案 1 :(得分:0)

您必须稍微修改CASE才能返回值:

WHERE 
  Case 
    WHEN :P1_JOB_SIZE_CHOOSER = 'Small'  AND (1440*(END_TIME - START_TIME)) <= 5 
      THEN 1
    WHEN :P1_JOB_SIZE_CHOOSER = 'Medium' AND (1440*(END_TIME - START_TIME)) > 5
                                         AND (1440*(END_TIME - START_TIME)) <= 20
      THEN 1
    WHEN :P1_JOB_SIZE_CHOOSER = 'Large' AND (1440*(END_TIME - START_TIME)) > 20
      THEN 1
    WHEN (1440*(END_TIME - START_TIME)) > 0
      THEN 1
  END = 1