Solved

Case Sensitivity in Oracle

Posted on 2004-10-14
11
2,163 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
11 Comments
 
LVL 12

Accepted Solution

by:
catchmeifuwant earned 125 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 125 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
 
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
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 shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

743 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now