Ask the Expert

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?

    Requires Free Membership to View

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:

   :new.ename := UPPER(:new.ename) ;
   :new.job := UPPER(:new.job) ;
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

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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: