0

Below works for SQL Server and MySQL, but how to modify it to work as proper Oracle query:

SELECT city FROM station WHERE LEFT(city, 1) IN ('a', 'e', 'i', 'o', 'u');

I'm stuck at:

SELECT city FROM station WHERE SUBSTR(city,1, 1) IN ('a', 'e', 'i', 'o', 'u');

?

Qbik
  • 5,460
  • 13
  • 52
  • 86

2 Answers2

1

Your query is perfectly OK provided that the cities you are interested in start with lowercase letters. If that's not the case you may want to use LOWER function:

SELECT city FROM station WHERE LOWER(SUBSTR(city,1, 1)) IN ('a', 'e', 'i', 'o', 'u');
Marcin Wroblewski
  • 3,461
  • 17
  • 26
1

If you want a version that works in all three databases you can use like:

SELECT s.city
FROM station s
WHERE LOWER(s.city) LIKE 'a%' OR
      LOWER(s.city) LIKE 'e%' OR
      LOWER(s.city) LIKE 'i%' OR
      LOWER(s.city) LIKE 'o%' OR
      LOWER(s.city) LIKE 'u%';
Gordon Linoff
  • 1,198,228
  • 53
  • 572
  • 709