Q

Setting up Oracle as case insensitive

I am converting a product built on SQL Server to Oracle 9i, and looking at differences between the two. One difference that will have a big impact is case sensitivity. The SQL Server database is set up as case insensitive, so we can group and combine output based on character data spelled the same but not necessarily with the same case. In other words WHERE FIRSTNAME = 'JOHN' returns JOHN, john, John, etc. I don't want to use SOUNDEX...

because I don't want Jon returned. Can Oracle be setup as case insensitive? If so, how?

You can use functions in your WHERE clause to compare:

   WHERE UPPER(firstname) = 'JOHN' 
There is also a LOWER() function and a INITCAP() function. Take your pick. That way no matter what the case of the value stored in the table, you'd always be comparing like case.

Using these functions however will cause indexes not to be used properly. So, you'd have to look into function-based indexes to maintain performance.

You could also force all data stored in the database to be stored in one case (for instance, all UPPER case). When you migrate your data you'd have to clean it all up to be all UPPER case and then after that you could simply write a BEFORE trigger to change the case the user enters to the case you wish to store.

For example:

CREATE OR REPLACE TRIGGER emptable_chg_case
BEFORE INSERT OR UPDATE ON emp
FOR EACH ROW
BEGIN
   :new.ename := UPPER(:new.ename) ;
   :new.job := UPPER(:new.job) ;
END ;
/
You'd simply include each text column for which you wish to control text into the trigger body code and when the user inserts or updates data in those columns the values they enter will automatically be changed to UPPER case.

For More Information


This was first published in May 2003

Dig deeper on Oracle database design and architecture

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close