Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2367
  • Last Modified:

Case Sensitivity in Oracle

Is oracle case sensitive? Im try to run the following query, SELECT * FROM Names WHERE Type LIKE Dagenham. The query does not return any values when i run it as  
SELECT * FROM Names WHERE Type LIKE '%dag%'
SELECT * FROM Names WHERE Type LIKE '*dag*'.
But when i run it as  SELECT * FROM Names WHERE Type LIKE '%Dag%' it works fine. The values in the field Type are stored as Dagenham. Please can anyone help with this. Thanks
2 Solutions
Oracle is not case sensitive...but the data stored within is case sensitive....

If you don't know how it is stored, then convert everything to a particular case and then do the comparison..

For eg., you can do :

FROM Names

So,everything stored in "type" is converted to UPPER Case and compared against "DAG"
Hi oagunbiade,
Yes, it is.  Sounds like your data has an initial capital followed by mainly lower case.
SELECT * FROM Names WHERE upper(Type) LIKE '*DAG*'
or even
SELECT * FROM Names WHERE lower(Type) LIKE '*dag*'
Wildcarding with LIKE is done with the '%' character, not the '*' character.

Also, converting to uppercase is always the correct way - this is a many-to-one conversion (consider languages with acents on lower case characters that do not have them on upper case characters!), converting to lowercase will always convert the capital to the lowercase without the accent!)

Oracle commands are case insensitive, but data is case-sensitive, as catchmeifuwant says.
So, use catchmeifuwant's suggestion...
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Actually you can create objects in Oracle with mixed-case table and field names.  It's a real pain if you do, though, because you have to enclose the name of the mixed-case object in double quotes any time you reference them in SQL.  For example if oagun's table name had been created with mixed-case columns, his select statement would have to look like:

SELECT * FROM "Names" WHERE upper("Type") LIKE '*dag*'

and woe betide him if he mis-spelt it at create stage and it was actually TYpe!!

oagunbiadeAuthor Commented:
Thanks everyone its solved my problem
dramacqueen, Don't understand what you are getting at...

Oracle is case-insensitive apart from the data stored in tables, etc... see my example session below... also, note the correct use of LIKE ('%' rather than '*' for wildcarding...)

SQL> CrEaTe TaBlE tEst_TabLe( nAmE varchar2(10) );

Table created.

SQL> iNsErT InTo TeST_tABLE( NaMe ) values( 'lower' );

1 row created.

SQL> insert into test_table( name ) values( 'UPPER' );

1 row created.

SQL> insert into test_table( name ) values( 'hello' );

1 row created.

SQL> insert into test_table( name ) values( 'HELLO' );

1 row created.

SQL> select count(*) from test_table where upper( name ) like '*ELL*';


SQL> select count(*) from test_table where upper( name ) like '%ELL%';


as you can see, tables created with names mixed cases, and column names mixed cases have no affect on the command line - only the contents are case-sensitive...


again, beware, LIKE uses '%' to represent a sequence of any characters, '*' has no special meaning in Oracle's LIKE function...
Hi cjjclifford
To achieve mixed case result, you'd have to include the double quotes in the create statement, viz:

Create taBLe "TesTtable" ("nAmE" varChar2(10) );

The mixed case in the sql words "create" and "table" and "varchar2" don't matter a jot.  But the mixed case in the table name and column name inside the quotes have to always be spelt the same thereafter.  The reason is that if you don't include quotes around table and field names, oracle assumes they are upper case.
Create taBLe TesTtable (nAmE varChar2(10) )
yields a table called TESTTABLE with a field called NAME, as does
Create table testtable (name varchar2(10) )

 - believe me I have an application I support whose designers thought it'd be neat to have mixed-case fieldnames (more readable, I believe was the reason...), and I have lived to regret their decision.
wow, what a really useless feature of Oracle...

sorry I doubted you....

yes, it does initially give the look of readability to a developer (which I am primarily!) but even in my developer mode I quickly see this being a REAL pain.... (I even wonder how would a column named like this be retrieved using something like JDBC where you can fetch results using column names..... probably have to pass in escaped quotes .... now that could never be though of as being MORE readable... :-)

No worries :)
>I even wonder how would a column named like this be retrieved using something like JDBC

Exactly!  Anyway I have learnt to use shift-2 one-handed - one advantage I suppose...
well, fast typing is obviously a definite skill... I wonder what damage to my wrists I've done over the years.... I'm only 30, but have the wrists of a 90 year old...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now