Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In SQL I want to display the names of all those cities which end with an vowel

Tags:

sql

oracle

I wrote the following query

SELECT UNIQUE 
    CITY 
FROM 
    STATION 
WHERE 
    (CITY LIKE '%A' OR 
     CITY LIKE '%E' OR 
     CITY LIKE '%I' OR 
     CITY LIKE '%O' OR 
     CITY LIKE '%U') 
ORDER BY 
    CITY;

What is wrong with this?

like image 421
Varun K R Avatar asked Aug 29 '15 09:08

Varun K R


1 Answers

I think you can use REGEXP_LIKE like this:

SELECT UNIQUE CITY 
FROM STATION 
WHERE REGEXP_LIKE(CITY, '[AaEeIiOoUu]$') 
ORDER BY CITY;
like image 103
shA.t Avatar answered Sep 22 '22 15:09

shA.t