title: Oracle SQL - Strange 'ORA-00907 Missing Right Parenthesis' error
body: <p>I've written a query to test out a simple linear regression to get the line of best-fit between two sets of weight measures. It should hopefully return results like below, but it's throwing a strange error</p>
  
  <p><strong>'ORA-00907 Missing Right Parenthesis'</strong> </p>
  
  <p>and TOAD is pointing towards the part where it says:</p>
  
  <pre><code>case ( when trn.wid_location = 28.3 then 
  </code></pre>
  
  <p>I've been combing it over for missing parenthesis but I don't think that's the issue because if I replace the case statement with</p>
  
  <pre><code>100 as mine,
  </code></pre>
  
  <p>the error disappears and the query executes.</p>
  
  <p>Any thoughts?</p>
  
  <p>Cheers,</p>
  
  <p>Tommy</p>
  
  <pre><code>select
        decode(wid_location,28.3,'CL',29.6,'DA') as site,
        (n*sum_xy - sum_x*sum_y)/(n*sum_x_sq - sum_x*sum_x) as m,
        (sum_y - ((n*sum_xy - sum_x*sum_y)/(n*sum_x_sq - sum_x*sum_x))*sum_x)/n as b 
  
  from (
          select 
                 wid_location,
                 sum(wids) as sum_x,
                 sum(mine) as sum_y,
                 sum(wids*mine) as sum_xy,
                 sum(wids*wids) as sum_x_sq,
                 count(*) as n
  
          from (                                                                        
                  select 
                         trn.wid_location,
                         con.empty_weight_total as wids,                                                                    
                         case ( 
                                when trn.wid_location = 28.3 then con.empty_weight_total*0.900-1.0
                                when trn.wid_location = 29.6 then con.empty_weight_total*0.950-1.5
                                end                
                              ) as mine   
  
                  from widsys.train trn
                       inner join widsys.consist con
                       using (train_record_id)
  
                  where mine_code = 'YA'
                        and to_char(trn.wid_date,'IYYY') = 2009
                        and to_char(trn.wid_date,'IW') = 29
  
                                   )
  
          group by wid_location
       )
  </code></pre>
  
  <p>And here are the results i'd be happy to see</p>
  
  <pre><code>--    +----------+--------+----------+
  --    | SITE     | M      | B        |
  --    +----------+--------+----------+
  --    | CL       | 0.900  | -1.0     |
  --    +----------+--------+----------+
  --    | DA       | 0.950  | -1.5     |
  --    +----------+--------+----------+
  </code></pre>