How to find the city name not starting and ending with a vowel

前端 未结 4 662
太阳男子
太阳男子 2021-01-28 04:56

I\'m trying to query the list of CITY names from STATION that do not start with vowels and do not end with vowels. The result cannot contain duplicates.

At first I tried

相关标签:
4条回答
  • 2021-01-28 05:41

    Your first query would be correct if you used AND rather than OR.

    You might find it the logic simpler as:

    where not (city like 'A%' or city like 'E%' or . . . ) and
          . . . 
    

    By the rules of logic, this is equivalent to:

    where city not like 'A%' and city not like 'E%' and . . . ) and
          . . . 
    

    As for the regular expression, it has only the comparison at the beginning of the string:

    where not regexp_like(lower(city), '^[aeiou].*[aeiou]$')
    
    0 讨论(0)
  • 2021-01-28 05:58

    A little easier to read would be:

        SELECT DISTINCT  CITY 
        FROM STATION 
        WHERE  SUBSTR(CITY,1,1) NOT IN ('A','E','I','O','U')
        AND SUBSTR(CITY,-1,1) NOT IN ('A','E','I','O','U');
    

    Note the -1 in the second WHERE clause which tells Oracle to search from the end of the string.

    0 讨论(0)
  • 2021-01-28 06:00

    There are 4 approach to achieve what you are trying to achieve. 1. In your first query change the or condition to and Condition 2. For the regex add comparison to end of string, currently it has only at beginning of string. regexp_like(lower(city), '^[aeiou].*[aeiou]$') 3. use substring to check for the first and last value of the string SELECT DISTINCT CITY FROM STATION WHERE SUBSTR(CITY,1,1) NOT IN ('A','E','I','O','U') AND SUBSTR(CITY,-1,1) NOT IN ('A','E','I','O','U'); 4. You can fetch the first and last letter of the city from table station and then check them against vowels using if condition and if there are no vowels you can return the value. Easiest and better approach would be 3 and 2.

    0 讨论(0)
  • 2021-01-28 06:01
    select distinct city from  station where regexp_like(city, '^[^EUIOA].*[^euioa]$');
    
    0 讨论(0)
提交回复
热议问题