Solved

Oracle SQL to find mixed case string values

Posted on 2016-08-08
11
206 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
[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
  • 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

733 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