Solved

Oracle SQL to find mixed case string values

Posted on 2016-08-08
11
140 Views
Last Modified: 2016-08-08
Hello Experts,

I'm trying to find values for a specific string field in an Oracle 12c database that contains mixed case letters. Can anyone help me with the correct syntax for accomplishing this? My field name is "dc.dscr". Thank you.
0
Comment
Question by:jsmith08
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 32

Expert Comment

by:awking00
ID: 41747727
Can you provide a little more definition on the kind of strings that meet you meaning of mixed case? (e.g. upper and lower case in the same word or capitalized words in the middle of a sentence, etc.)?
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 41747748
mixed case would mean it's not ALL-UPPER nor  ALL-LOWER.


select * from yourtable
where not (upper("dc.dscr") = "dc.dscr" or lower("dc.dscr") = "dc.dscr")

As a side node, if you can avoid it, I recommend not using quote-enclosed column names.
It's non-standard and makes your coding more cumbersome to use.
0
 

Author Comment

by:jsmith08
ID: 41747777
I tried using:

 select * from dktcd dc
where not (upper('dc.dscr') = 'dc.dscr' or lower('dc.dscr') = 'dc.dscr')

but nothing is returned.

I want to be able to pull string values like the following:

Defendant ordered to attend Alcoholics Anonymous meetings ___ times per week.
Administrative license suspension (ALS) terminated.
Attorney of record is: ________________.

as opposed to just something like DEFT TO BE ASSESSED WHILE IN CUSTODY
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 32

Expert Comment

by:awking00
ID: 41747787
Are you just trying to retrieve strings that are not all upper or lower case? If so ,then slight revision to sdstuber's method -
where dc.dscr != upper(dc.dscr) or dc.dscr != lower(dc.dscr)
0
 
LVL 4

Expert Comment

by:Abhimanyu Suri
ID: 41747804
select 'Defendant ordered to attend Alcoholics Anonymous meetings ___ times per week.
Administrative license suspension (ALS) terminated.
Attorney of record is: ________________.' from dual


select * from v$sqlarea where upper(sql_text) like upper('%Defendant ordered%')

Above is an example, by putting upper on both sides, I was able to fetch the entire string.

Please note that using upper may degrade performance.
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 41747807
you changed what I posted  (note you changed double quotes, to single quotes) , but based on your change, I'm going to guess you want this

 select * from dktcd dc
 where not (upper(dc.dscr) = dc.dscr or lower(dc.dscr) = dc.dscr)
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 41747811
but just in case the double quotes are required try this...    

 select * from dktcd dc
  where not (upper(dc."dscr") = dc."dscr" or lower(dc."dscr") = dc."dscr")


(again, don't try changing double quotes to single quotes)
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 41747816
also note,  awking00's  "slight revision" of my query  does NOT work.

EVERY not null string will always be found by that revision.

use one of the versions I posted.

rearranging the conditiosn of my query would use "and" not "or"  between the two negations

select * from dktcd dc
where dc.dscr != upper(dc.dscr) and dc.dscr != lower(dc.dscr)
0
 

Author Comment

by:jsmith08
ID: 41747838
Ok, I tried using

select * from dktcd dc
 where not (upper(dc.dscr) = dc.dscr or lower(dc.dscr) = dc.dscr)

without any quotes and it works as desired. Thank you very much! I thought I needed to include the quotes for some reason.

I also tried using

select * from dktcd dc
 where dc.dscr != upper(dc.dscr) or dc.dscr != lower(dc.dscr)

but it returns values with all upper case letters in addition to values with upper and lower case letters.
0
 
LVL 32

Expert Comment

by:awking00
ID: 41747853
Should have been AND and not OR :-(
0
 

Author Comment

by:jsmith08
ID: 41747871
Thank you everyone for your help.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.

792 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