0

I was just wondering how you would search for any mix of case. For instance, I want to find all employees with the last name 'davies', but I want to be able to find any mix of case such as 'DavIes' or 'DAVies'. This is what I've tried.

SELECT LAST_NAME

FROM EMPLOYEES

WHERE DEPARTMENT_ID = (SELECT DEPARTMENT_ID

FROM EMPLOYEES

WHERE LAST_NAME = '[Dd][Aa][Vv][Ii][Ee][Ss]');
Glaz
  • 109
  • 1
  • 3
  • 10
  • I'd write a function based index which UPPER or LOWERs the name. This way the database can use the function based index to search instead of just the last_name. [Docs](https://docs.oracle.com/cd/E11882_01/appdev.112/e41502/adfns_indexes.htm#ADFNS257) – xQbert Oct 11 '17 at 20:18
  • 1
    Possible duplicate of [Case insensitive searching in Oracle](https://stackoverflow.com/questions/5391069/case-insensitive-searching-in-oracle) – xQbert Oct 11 '17 at 20:21

2 Answers2

1

I would use UPPER or LOWER function and IN

SELECT LAST_NAME
FROM EMPLOYEES
WHERE DEPARTMENT_ID IN (
   SELECT DEPARTMENT_ID
   FROM EMPLOYEES
   WHERE UPPER(LAST_NAME) = 'DAVIES'
);

Unfortunately it invalidates the index use.

Radim Bača
  • 10,646
  • 1
  • 19
  • 33
1

Using UPPER

SELECT *
   FROM EMPLOYEES
   WHERE UPPER(LAST_NAME) = 'DAVIES'
RoMEoMusTDiE
  • 4,739
  • 1
  • 17
  • 26