?
Solved

Case Sensitivity in Oracle

Posted on 2004-10-14
11
Medium Priority
?
2,196 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:oagunbiade
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 12

Accepted Solution

by:
catchmeifuwant earned 500 total points
ID: 12306562
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 :

SELECT *
FROM Names
WHERE UPPER(Type) LIKE '%DAG%'

So,everything stored in "type" is converted to UPPER Case and compared against "DAG"
0
 
LVL 2

Assisted Solution

by:dramacqueen
dramacqueen earned 500 total points
ID: 12306576
Hi oagunbiade,
Yes, it is.  Sounds like your data has an initial capital followed by mainly lower case.
Try
SELECT * FROM Names WHERE upper(Type) LIKE '*DAG*'
or even
SELECT * FROM Names WHERE lower(Type) LIKE '*dag*'
0
 
LVL 11

Expert Comment

by:cjjclifford
ID: 12306590
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...
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 2

Expert Comment

by:dramacqueen
ID: 12306607
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!!


0
 

Author Comment

by:oagunbiade
ID: 12306647
Thanks everyone its solved my problem
0
 
LVL 11

Expert Comment

by:cjjclifford
ID: 12306654
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.

0
 
LVL 11

Expert Comment

by:cjjclifford
ID: 12306657
again, beware, LIKE uses '%' to represent a sequence of any characters, '*' has no special meaning in Oracle's LIKE function...
0
 
LVL 2

Expert Comment

by:dramacqueen
ID: 12307284
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.
0
 
LVL 11

Expert Comment

by:cjjclifford
ID: 12307586
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... :-)

0
 
LVL 2

Expert Comment

by:dramacqueen
ID: 12307849
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...
0
 
LVL 11

Expert Comment

by:cjjclifford
ID: 12307912
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...
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question