Link to home
Start Free TrialLog in
Avatar of oagunbiade
oagunbiade

asked on

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%'
or
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
ASKER CERTIFIED SOLUTION
Avatar of catchmeifuwant
catchmeifuwant

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cjjclifford
cjjclifford

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...
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!!


Avatar of oagunbiade

ASKER

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*';

  COUNT(*)
----------
         0

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

  COUNT(*)
----------
         2

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...


Cheers,
C.

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.
So
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...