https://www.hackerrank.com/challenges/weather-observation-station-6/problem

 

Weather Observation Station 6 | HackerRank

Query a list of CITY names beginning with vowels (a, e, i, o, u).

www.hackerrank.com

코드설명

REGEXP_LIKE + LIKE  를 활용합니다.

 

REGEXP_LIKE를 활용할경우 코드가 훨씬 짧아집니다. 또한, 'i'(IGNORE CASE) 로 대/소문자 구분또한 자동으로 처리해줍니다.

ORACLE 코드

REGEXP_LIKE를 활용할경우

SELECT DISTINCT CITY
FROM STATION
WHERE REGEXP_LIKE(CITY, '^(a|e|i|o|u)', 'i');

 

LIKE 를 활용할경우

SELECT DISTINCT CITY
FROM STATION
WHERE CITY LIKE 'a%' OR CITY LIKE 'A%'
   OR CITY LIKE 'e%' OR CITY LIKE 'E%'
   OR CITY LIKE 'i%' OR CITY LIKE 'I%'
   OR CITY LIKE 'o%' OR CITY LIKE 'O%'
   OR CITY LIKE 'u%' OR CITY LIKE 'U%';

 

위와 같이 안하고 CITY를 LOWER함수로 바꿔어서 처리도 가능합니다.

그렇다면 와일드패턴도 적어지겠지요.

SELECT DISTINCT CITY
FROM STATION
WHERE LOWER(CITY) LIKE 'a%'
   OR LOWER(CITY) LIKE 'e%'
   OR LOWER(CITY) LIKE 'i%'
   OR LOWER(CITY) LIKE 'o%'
   OR LOWER(CITY) LIKE 'u%';

+ Recent posts