oracle sql query for selecting Even number columns

Viewed 48

In oracle sql when I am trying to get the output for the below, it is throwing error.

select city,id from station where id % 2 = 0;

Error:

ORA-00911: invalid character
00911. 00000 -  "invalid character"
*Cause:    identifiers may not start with any ASCII character other than
           letters and numbers.  $#_ are also allowed after the first
           character.  Identifiers enclosed by doublequotes may contain
           any character other than a doublequote.  Alternative quotes
           (q'#...#') cannot use spaces, tabs, or carriage returns as
           delimiters.  For all other contexts, consult the SQL Language
           Reference Manual.
1 Answers

The % operator for modulo is not supported in Oracle. You would need to use function mod():

select city,id from station where mod(id, 2) = 0;

Demo on DB Fiddle

Related