I have been trying to write a SQL query to get city names start and end with vowels only.
Code:
select distinct city
from station
where REGEXP_LIKE (city, '^(a|e|i|o|u).*(a|e|i|o|u)$');
This above query gives me the wrong answer. I am using Oracle.
>Solution :
Here is a more concise way to write your query using REGEXP_LIKE:
SELECT DISTINCT city
FROM station
WHERE REGEXP_LIKE(city, '^[aeiou].*[aeiou]$', 'i');
The third match parameter i tells Oracle to do a case insensitive search. This frees us from the need of listing out uppercase and lowercase vowels.