简体   繁体   中英

What is the difference between following SQL queries containing REGEXP_LIKE()?

select distinct first_name 
from EMPLOYEES 
where regexp_like(first_name,'^[^AEIOU]*[^aeiou]$');    

select distinct first_name 
from EMPLOYEES 
where regexp_like(first_name,'^[^AEIOU].*[^aeiou]$');  

I am trying to find Employee's first name's that doesn't start with and end with a vowel. I came up with above queries. Now I have two questions:

  1. Do the above statements return valid output (doesn't start and with vowel).

  2. Do the above statements return same result always (I get same result when I tried).

But when I tried the below two queries they gave different outputs with respect to each other

select distinct first_name 
from EMPLOYEES 
where regexp_like(first_name,'^[AEIOU]*[aeiou]$');    

select distinct first_name 
from EMPLOYEES 
where regexp_like(first_name,'^[AEIOU].*[aeiou]$');         

1) The two first queries don't give you valid ouput. They match names that start with lowercase vowels or end with uppercase vowels. And they don't give always the same result:

  • Marcos is a match for the first and the second
  • MARCOS is a match for the second and not the first
  • allan is a match for both

2) The second pair presents different output for similar reasons.

You can try it yourself: Regular expressions 101

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM