ORA-00920: invalid relational operator

Oh Chin Boon picture Oh Chin Boon · May 26, 2012 · Viewed 14.4k times · Source

This SQL query seems to be hitting ORA 00920.

select username, count(*)
from host
where created_dt 
between to_date('2012-may-23 00:00:00', 'yyyy-mon-dd hh24:mi:ss') 
and to_date('2012-may-23 23:59:59', 'yyyy-mon-dd hh24:mi:ss')
GROUP BY CASE
             WHEN REGEXP_LIKE(username, '^\d+$') THEN 'GRP_OTHERS'
                                                 ELSE username
         END;

Answer

jswolf19 picture jswolf19 · May 26, 2012

I don't have an Oracle DB to play with, but I imagine it could be because you select username but don't group by it. You should be able to get around that by using a subquery:

select username, count(*)
from (select CASE
             WHEN REGEXP_LIKE(username, '^\d+$') THEN 'GRP_OTHERS'
                                                 ELSE username
         END as username
      from host
      where created_dt 
      between to_date('2012-may-23 00:00:00', 'yyyy-mon-dd hh24:mi:ss') 
          and to_date('2012-may-23 23:59:59', 'yyyy-mon-dd hh24:mi:ss')
     )
GROUP BY username;