SQL error: Missing keyword?

86 views Asked by At

I'm getting a missing keyword error here. I recently added the WHERE clause and that's when the missing keyword error came up.

 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)

Any help would be appreciated.

2

There are 2 answers

0
krokodilko On

Do it in this way:

....
....
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 
0
dnoeth On

You must slightly modify your CASE to return a value:

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