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.
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
- Dozens more answers to tough Oracle questions from Karen Morton are available.
- The Best Oracle Web Links: tips, tutorials, scripts, and more.
- Have an Oracle or SQL tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
- Ask your technical Oracle and SQL questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.
This was first published in May 2003