Solved

Oracle SQL to find mixed case string values

Posted on 2016-08-08
11
278 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
Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

 
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 5

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

717 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